Can I choose a style?

Is there a way for the selector to select a style element that can be used in the layout with @style? In particular, I am trying to change TextView elements, such as color and shadow, based on state_pressed, state_focused and state_selected. I tried several XML selector, element and style XML schemas and was not successful.

+3
source share
1 answer

Your problem is solved with @drawable but not used by @style

create one xml file containing one button ...

<Button android:id="@+id/button1"
        android:layout_centerHorizontal="true" android:layout_centerVertical="true"
        android:layout_height="50dip" android:layout_width="150dip"
        android:text="Click To Check Style" android:background="@drawable/ef_button"></Button>

and create on the dropdown folder in res .. create one ef_button.xml file

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <!--  <color android:color="#800517" />-->
        <shape>
            <gradient android:startColor="#FFFF00" android:endColor="#AF7817"
                android:angle="270" />
            <stroke android:width="5dp" android:color="#747170" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="10dp"
                android:right="10dp" android:bottom="10dp" />

        </shape>
    </item>
    <item android:state_focused="true">
        <!--  <color android:color="#00FFFF" />-->
        <shape>
            <gradient android:endColor="#F433FF" android:startColor="#F6358A"
                android:angle="270" />
            <stroke android:width="5dp" android:color="#747170" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="10dp"
                android:right="10dp" android:bottom="10dp" />
        </shape>

    </item>
    <item>
        <!-- <color android:color="#FFFFFF" /> -->
        <shape>
            <gradient android:endColor="#A0CFEC" android:startColor="#736AFF"
                android:angle="270" />
            <stroke android:width="5dp" android:color="#747170" />
            <corners android:radius="5dp" />
            <padding android:left="10dp" android:top="10dp"
                android:right="10dp" android:bottom="10dp" />
        </shape>

    </item>
</selector>

The same thing that you can use TextView ... set some textview properties ...

TxtVw.setClickable(true);
TxtVw.setFocusable(true);

try it.

+6
source

All Articles