0

i have a ListView in my Navigation Drawer and want it looks like the Playstore App or Youtube App.

Means onClick changing FontColor for Example to red and when i just hold it the background should turn grey.

Do i have to use 2 onitemclicklistener?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp">

<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/DrawerListIcon"
    android:src="@drawable/ic_home"
    android:layout_centerVertical="true" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/icon"
    android:textSize="14sp"
    android:textStyle="bold"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/DrawerListFontColor"
    android:gravity="center_vertical"
    android:paddingRight="40dp"
    android:paddingLeft="0dp"/>
</RelativeLayout>

Tried with Item and Selector. First thing Font Color don't change when i pressed the Button. Second the background of the Relative Layout turns blue insead of Grey.

drawer_list_font.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_focused="true"
    android:color="@color/DrawerListFontColorPressed"
    />
<item android:color="@color/DrawerListFontColor"/></selector>

drawer_list_background.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_focused="true"
    android:color="@color/DrawerListBackgroundFocused"
    />
<item
    android:color="@color/DrawerBackground"
    /></selector>

I had to use android:drawable instead of background on the relative Layout. On the Textview Android Stuio accepted android:color.

Nick
  • 135
  • 1
  • 4
  • 13

2 Answers2

0

This is changed by changing view from ur java file at every click event u can change the view. U have to make multiple view ie xml files for that. Which are dynamically changed or u can also send parameters to a function and create an xml at runtime but that will be too deep for u

0

No need for listeners at all. A better approach here is to create drawable XML's with definitions for every state ("pressed", "focused", etc). Check out Color State List resources

For example:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:state_pressed="false"android:color="#80000" />
    <item android:state_focused="true" android:state_pressed="true" android:color="#ff0000" />
    <item android:state_focused="false" android:state_pressed="true" android:color="#ff0000" />
    <item android:color="@color/DrawerListFontColor" />
</selector>
Mr_Milky
  • 155
  • 9
  • Ok thanks. This was what i am looking for. Unfortunaly it doesn't work so well. Can you tell me what's wrong. See at my first post. – Nick Dec 15 '14 at 19:57