0
I implemented a Navigation Drawer (no modifications to the Android Developers example) I only changed the background colors of Listview and Text of the items:
layout/activity_main.xml:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
The drawer is given a fixed width in dp and extends the full height of
the container. A solid background is used for contrast
with the content view. -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:background="#ffe1e1e1"/>
</android.support.v4.widget.DrawerLayout>
layout/drawer_list_item.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?android:attr/activatedBackgroundIndicator">
<ImageView
android:id="@+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@string/list_item_icon"
android:src="@drawable/ic_logo_icone"
android:layout_centerVertical="true"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingLeft="45dp"
android:paddingRight="16dp"
android:textColor="#ff555555"
android:textStyle="bold"
android:hint="@string/item_desc"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
</RelativeLayout>
And here comes my Navigation Drawer:
The problem, as you can see, is that when the item is selected, the blue color superimposes the Icone leaving it more erased, and the text color is also superimposed having a slight shade change.
I would like my icone and my text to have no color change, to be blue only in the white areas of the view. I’ve tried my Xmls settings and tried doing other things programmatically too, but nothing solved.
I believe your icons are with alpha, so the blue color overlap, try to put a color in the
background
ofImageView
, possibly equal to the background of the item, to see if it contrasts.– Wakim
no use adding color to
background
ofImageView
, continues with the same problem.– Ighor Augusto
Try to make a separate selector and put it in the background of your list_item Relative instead of ? android:attr/activatedBackgroundIndicator. .
– Helder
in my
RelativeLayout
ofdrawer_list_item
I already put the attributeandroid:background="?android:attr/activatedBackgroundIndicator"
, but I don’t make a separate selector. I usemDrawerList.setSelection(position);
to make selector.– Ighor Augusto
just tried to make separate selector with the function:
mRelativeLayout.setBackground(getResources().getColor(R.color.blue));
but it didn’t work. The text I was able to solve, but the icon, it won’t work at all! :(– Ighor Augusto