【问题标题】:Style EditText underline color android样式EditText下划线颜色android
【发布时间】:2016-05-17 08:58:46
【问题描述】:

我正在创建一个应用程序,它有几个编辑文本,当编辑文本有焦点或没有焦点时会改变颜色。当视图具有焦点时,颜色应该是蓝色,正常时应该是白色,如下所示:

我尝试创建两个九个补丁并根据此 xml 设置背景,但似乎它不起作用。谁能告诉我怎样才能做到这一点?

Xml 选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="true" android:state_focused="true"
        android:drawable="@drawable/spelling_blue" />
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/spelling_white" />
    <item android:drawable="@drawable/spelling_white" />
</selector>

谢谢

【问题讨论】:

  • 试试这个stackoverflow.com/questions/35262935/…希望它对你有帮助。
  • 你有什么资源?你能显示 spelling_blue 和 spelling_white 吗?
  • 尝试 schemas.android.com/apk/res/android">

标签: android android-edittext android-xml android-background


【解决方案1】:

我认为你不需要使用android:state_window_focused

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_pressed="true"
        android:drawable="@drawable/spelling_blue" /> <!-- pressed -->    
    <item 
        android:state_focused="true"
        android:drawable="@drawable/spelling_blue" /> <!-- focused -->    
    <item 
        android:drawable="@drawable/spelling_white" /> <!-- default -->
</selector>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2017-07-23
    • 2018-08-13
    • 2016-09-03
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    相关资源
    最近更新 更多