开发者

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_se开发者_开发技巧lected. I have tried multiple XML arrangements of selector, item and style and have not been succesful.


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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜