0

I need to change selected item color in such condition that mentioned below. Is it possible to do it by drawable selector xml file? I can change layout inclusion with listview if it works.

I need to change any of one:

1) Tint of ImageView along with TextView text color

2) LinearLayout background that holding both TextView and ImageView

Navigationview

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start">
       <include layout="@layout/custommenu"/>
</android.support.design.widget.NavigationView>

custommenu.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/selector"
        android:gravity="center_horizontal">

        <ImageView
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:tint="@color/white"
            app:srcCompat="@drawable/ic_home_24dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Home"
            android:textColor="@color/white"
            android:textSize="16sp" />
</LinearLayout>

selector.xml

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

Don't mark it duplicate if you cannot show me the exact match of my condition. If you cannot answer just ignore it please.

Thanks in advance.

Fresco
  • 343
  • 3
  • 13
  • What selected item are you trying to change the color of? – 0xCursor Feb 10 '18 at 05:39
  • The `LinearLayout` that holding both `ImageView` and `TextView` – Fresco Feb 10 '18 at 05:42
  • So to be clear, that is the background? – 0xCursor Feb 10 '18 at 05:44
  • Yes, but changing tint of `ImageView` along with `TextView` color will be much better – Fresco Feb 10 '18 at 05:45
  • Is [this](https://stackoverflow.com/questions/32471009/what-is-the-difference-between-background-backgroundtint-backgroundtintmode-at) kind of what you are looking for? [This](https://stackoverflow.com/questions/5576822/change-background-of-linearlayout-in-android) also relates to `LinearLayout` and [this](https://stackoverflow.com/questions/20121938/how-to-set-tint-for-an-image-view-programmatically-in-android) for `ImageView`. – 0xCursor Feb 10 '18 at 05:50
  • None of them. Please take a look at my updated thread. – Fresco Feb 10 '18 at 05:58
  • You have had enough fun. No more please – Fresco Feb 10 '18 at 06:01

0 Answers0