Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a style selector possible?

Is there a way to have a selector select a style element that can be used in a layout using @style? Specifically I'm trying to change TextView elements such as color and shadow based on state_pressed, state_focused and state_selected. I have tried multiple XML arrangements of selector, item and style and have not been succesful.

like image 991
miguel Avatar asked Jun 09 '11 10:06

miguel


1 Answers

your problem is solve using @drawable but not using @style

create one xml file contain 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 drawable 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>

same thing you can using TextView... set some textview properties...

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

try it..

like image 164
Kundan Chaudhary Avatar answered Oct 13 '22 21:10

Kundan Chaudhary