Reputation: 295
I create DrawerLayout with ListView. When I swipe menu I see this menu, but another side still white. I wanna change backgroun color when Drawer open and change it color when move navigation from left to right like in Gmail or Play market.
My activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ListView) findViewById(R.id.left_drawer);
DrawerItemObject[] drawerListItems = {
new DrawerItemObject("Las news"),
new DrawerItemObject("MEG")
};
drawerList.setAdapter(new DrawerItemAdapter(this, R.layout.left_drawer_listview_item_row, drawerListItems));
drawerLayout.setScrimColor(Color.BLACK);
}
setScrimColor not work
And activity_layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:background="#111"
>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
>
</ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Upvotes: 0
Views: 839
Reputation: 295
In my activity_main layout I forgot add
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<!-- Add FrameLayout -->
<!-- NEW CODE STRART-->
<FrameLayout android:id="@+id/frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- NEW CODE END-->
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:background="#111"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello"
android:textColor="#fff"
/>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
>
</ListView>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Upvotes: 2
Reputation: 2417
setScrimColor
void setScrimColor (int color) Set a color to use for the scrim that obscures primary content while a drawer is open.
Upvotes: 0