文本视图中的样式不起作用

时间:2015-04-28 13:23:07

标签: android

我有textview样式:

<style name="MoreSettingsItem">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">@dimen/drivelog_7BU</item>
    <item name="android:background">@drawable/textview_white_selector</item>
    <item name="android:drawablePadding">@dimen/drivelog_2BU</item>
    <item name="android:drawableRight">@drawable/arrow_right</item>
    <item name="android:gravity">center_vertical</item>
    <item name="android:textSize">14sp</item>
    <item name="android:fontFamily" tools:ignore="NewApi">sans-serif</item>
    <item name="android:paddingLeft">@dimen/drivelog_BU</item>
    <item name="android:paddingRight">@dimen/drivelog_2BU</item>
</style>

我想添加边框,所以我添加:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/textview_white_pressed" android:state_pressed="true"/>
    <item android:drawable="@color/white"/>
    <item android:drawable="@drawable/textview_bottom_line"/>
</selector>

<?xml version="1.0" encoding="utf-8"?>

<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/background_color"/>
    <item android:drawable="@color/selector_color"/>
    <item android:drawable="@drawable/textview_bottom_line"/>
</transition>

但这个解决方案不起作用。知道为什么吗?

1 个答案:

答案 0 :(得分:1)

您必须区分具有不同状态的每个项目标记。因为如果没有向item标签提及任何状态,它将把该项目作为默认项目。但在你的选择器中你有两个不同的项目只有drawable然后它不会工作删除选择器中的一个项目标签然后它将工作。修改如下

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/textview_white_pressed" android:state_pressed="true"/>
    <item android:drawable="@color/white"/>
</selector>


<?xml version="1.0" encoding="utf-8"?>

<transition xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:drawable="@drawable/textview_bottom_line"/>
</transition>

如果你想添加任何border.or任何其他修改然后创建自定义形状并将其分配给drawable将工作。我希望。