android - 更改 EditText 的焦点颜色?

标签 android themes

如何在获得焦点时更改 EditText 的颜色?在模拟器中,聚焦时它是蓝色的,我看不到从 XML 布局或以编程方式更改它的方法。我无法弄清楚如何更改其他 View 以及按钮和微调器的焦点颜色。 The selected colour of the EditText blue

最佳答案

yourEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

                public void onFocusChange(View v, boolean hasFocus) {
                    if (v == yourEditText)
                    {
                        if (hasFocus)
                        {
                           yourEditText..setTextColor(Color.RED);

                        } 
                        else
                        { 

                        }
                    }

                }
            });

为此使用焦点监听器(按钮等)

编辑 您必须使用 XML 并为此设置 View 的背景

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

干杯

关于android - 更改 EditText 的焦点颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14314212/

相关文章:

android - 带有 JQM for android 的 Phonegap 中的字符串值配置文件

javascript - 如何使用 CSS 和 JavaScript 制作可变主题

Eclipse 的包资源管理器背景颜色遵循 Windows 主题。我想在不改变 Windows 主题的情况下改变颜色。可能的?

Android::如何以编程方式更改其他 apk 的主题

themes - Liferay:网站 Logo

android - 如何从内容 ://mms. 中检索彩信的日期

Android 添加没有事务的 fragment

java - 为什么即使在 settings.xml 文件中声明了 PreferenceCategory 的摘要也没有得到它?

android - 为 NavigationView 保存实例?

html - Hugo 没有生成与开发模式相同的样式