我无法使用选择器添加样式

时间:2012-09-06 07:59:30

标签: android

我有风格

<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="TextStyle" > 
        <item name="android:textSize">8sp</item> 
        <item name="android:textColor">#0A0A0A</item> 
        <item name="android:typeface">serif</item> 

</style>

 <style name="TextStylePressed" > 
        <item name="android:textSize">18sp</item> 
        <item name="android:textColor">#0A0A0A</item> 
        <item name="android:typeface">serif</item> 
        <item name="android:textStyle">bold</item> 
        <item name="android:background">#C2C2C2</item>   
</style>

</resources>

我使用了selector arrow.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@style/TextStylePressed" android:state_selected="true"/>
    <item android:drawable="@style/TextStylePressed" android:state_pressed="true"/>
    <item android:drawable="@style/TextStylePressed" android:state_focused="true"/>
    <item android:drawable="@style/TextStyle" />

</selector>

问题是我无法理解 - 如果有效?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@drawable/arrow"               //  <---- Framed here
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/arrow" //  <---- then here
    android:orientation="vertical" > 

</LinearLayout>

因此,在所有尝试都没有发生之后

1 个答案:

答案 0 :(得分:1)

AFAIK选择器只能定义为选择drawable而不是任何其他attribute。如果你检查doc,它会编译成StatelistDrawable,所以我相信它只能用于drawables