Android EditText底线颜色和主题更改 [英] Android EditText bottom line color and theme changes

查看:79
本文介绍了Android EditText底线颜色和主题更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要删除edittext默认样式我要从编辑文本焦点或普通编辑文本的两侧都删除选定的部分,我只希望简单的黑线在正常的edittext和焦点上的蓝线

hello all i need to remove the edittext default style i want to remove the selected portion from both the side on focus of edittext or on normal edittext i just want the simple black line on normal edittext and blue line on focus

我创建了1个xml:

 <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">

        <item android:state_pressed="true"><shape android:shape="line">

                <!-- Draw a 2dp width border around shape -->
                <stroke android:width="1dp" android:color="@color/blue" />
            </shape>
               <!-- Overlap the left, top and right border using background color  -->
        <item
            android:bottom="1dp"
            >
            <shape android:shape="rectangle">
                <solid android:color="@color/white"/>
            </shape>
        </item> <!-- pressed -->
        </item>
        <item android:state_focused="true"><shape android:shape="rectangle">

                <!-- Draw a 2dp width border around shape -->
                <stroke android:width="1dp" android:color="@color/blue" />
            </shape></item>
     <!-- focused -->
        <item><shape android:shape="rectangle">

                <!-- Draw a 2dp width border around shape -->
                <stroke android:width="1dp" android:color="@color/orange" />
            </shape></item>
     <!-- default -->

    </selector>

但是它给了我矩形,我只想要LINE @bottom

but it giving me RECTANGLE i just want LINE @bottom

推荐答案

在drawable文件夹中创建新的xml文件. 可以说

Create the new xml file inside drawable folder. lets say

a.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" /> <!--background color of box-->
        </shape>
    </item>

    <item
        android:top="-2dp"
        android:right="-2dp"
        android:left="-2dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="1dp"
                android:color="<Focus color>" />  <!-- color of stroke -->
        </shape>
    </item>
</layer-list>

在drawable中创建另一个新的xml文件,可以说

Create another new xml file in drawable, lets say

b.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" /> <!--background color of box-->
        </shape>
    </item>

    <item
        android:top="-2dp"
        android:right="-2dp"
        android:left="-2dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="1dp"
                android:color="#8AC42F" />  <!-- color of stroke -->
        </shape>
    </item>
</layer-list>

在drawable中创建另一个新的xml文件. 可以说

Create another new xml file in drawable. lets say

c.xml

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

尝试此代码.

这是一个选择器文件.必须使其成为edittext的背景. 选择器会根据其(编辑文本)状态自动在两个可绘制文件之间切换.

this is a selector file. it has to be made background to the edittext. selector automatically switches between two drawable file acording to its (edittext's) state.

使用 EditText

<EditText
    android:id="@+id/id_Login_emal_et"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:background="@drawable/c"
    android:ems="10"
    android:padding="10dip"
    android:hint="Email"
    android:inputType="textEmailAddress"
    >

这篇关于Android EditText底线颜色和主题更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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