如何改变焦点颜色的EditText的安卓 [英] how to change focus color of EditText in Android

查看:431
本文介绍了如何改变焦点颜色的EditText的安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能改变焦点颜色(橙色)的一个EditText框?该 焦点颜色是围绕整个控制小轮辋和亮 橙色当控件具有焦点。我如何可以改变的颜色 专注于不同的颜色? 谁能帮我整理出这个问题? 在此先感谢,

How can I change the focus color (orange) on an EditText box? The focus color is a small rim around the entire control and is bright orange when the control has focus. How can I change the color of that focus to a different color? Can anyone help me in sorting out this issue? Thanks in advance,

推荐答案

您必须创建/修改自己的NinePatch形象,以取代默认的,并使用它作为您的EditText的背景。如果你看看你的SDK文件夹,你的平台下,然后RES /绘制,你应该找到NinePatch形象为重点的EditText状态。如果这是你想改​​变,你可以把它导入到Photoshop,或任何图像编辑软件你有,变橙色到你所选择的颜色。然后保存到你的绘制文件夹,并建立一个新的StateListDrawable,比如像下面的:

You'll have to create/modify your own NinePatch image to replace the default one, and use that as the background of your EditText. If you look in your SDK folder, under your platform, then res/drawable, you should find the NinePatch image for the EditText focus state. If that's all you want to change, you can just pull it into Photoshop, or whatever image editing software you have, and change the orange color to a color of your choosing. Then save that into your drawable folder, and build a new StateListDrawable, for example something like the below:

edittext_modified_states.xml

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

我不知道随便的实际名称为默认NinePatches的EditText上,所以那些在必要时更换,但这里的关键是只使用了 @android:绘制图像,没有修改的那些(或者您可以通过将它们复制到项目的绘制文件夹),然后用修改后的绘制你的聚焦状态。

I don't know offhand the actual names for the default NinePatches for the EditText, so replace those as necessary, but the key here is to just use the @android:drawable images for the ones you haven't modified (or you can copy them over to your project's drawable folder), and then use your modified drawable for your focused state.

您可以再设置这个StateListDrawable为背景为您的TextView,像这样:

You can then set this StateListDrawable as the background for your TextView, like so:

<TextView
    android:background="@drawable/edittext_modified_states"

这篇关于如何改变焦点颜色的EditText的安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆