2012-09-06 36 views
0

添加样式我的风格我不能使用选择

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

我用选择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

你的文件是否真的名为'Arrow.xml'(第一个字母的上部)? – hsz

+0

对不起,我犯了一个错误arrow.xml –

回答

1

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

+0

难以理解我做了什么错误你的意思是说应该有“@ drawable/TextStylePressed “? –

+0

是的,只有drawables工作的选择器。所以你不能设置android:textColor或任何其他属性通过选择器 – nandeesh

+0

告诉我请创建一个LinearLayout android:background =“@ drawable/arrow”它的工作原理,但不工作为什么? –