zoukankan      html  css  js  c++  java
  • Android 自定义android控件EditText边框背景

    在我们进行Android应用界面设计和时候,为了界面风格的统一,我们需要对一些控件进行自定义。比如我们的应用采用的蓝色风格,但是 android的EditText控制获得焦点后显示的却是黄色的边框背景。那么如何让EditText在获得焦点的时候显示的是我们自定义的蓝色的背景 呢?

    首先准备两张图片,一张是EditText获得焦点后的边框背景,一张是没有获得焦点时的背景,注意制作成9.png样式的图片,然后在drawable里添加一个selector_edittext_bg.xml文件,内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/edit_pressed" android:state_focused="true"/>
        <item android:drawable="@drawable/edit_normal"/>
    
    </selector>

    然后在values文件夹下新建一个style.xml文件,内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <style name="my_edittext_style" parent="@android:style/Widget.EditText">
            <item name="android:background">@drawable/selector_edittext_bg</item>
        </style>
    
    </resources>

    最后在EditTex上使用我们新建的样式就可以了:

    <EditText
                android:id="@+id/v_value"
                style="@style/my_edittext_style"
                android:layout_width="0.0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="@string/edit_key"
                android:imeOptions="actionDone"
                android:inputType="" />

  • 相关阅读:
    python file op
    python write read
    Linux MD RAID 10
    bitmap.h
    1
    write 1 to block device
    tr '00' '377' < /dev/zero | dd of=/dev/$i bs=1024 count=1024000
    Superblock
    echo -e "33[41;36m something here 33[0m"
    May It Be
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4270086.html
Copyright © 2011-2022 走看看