Android EditText底线颜色和主题更改

Android EditText底线颜色和主题更改,android,android-edittext,themes,Android,Android Edittext,Themes,您好,我需要删除edittext默认样式我想删除edittext焦点两侧或普通edittext上的选定部分我只想在普通edittext上使用简单的黑线,在焦点上使用蓝线 我创建了1个xml: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:st

您好,我需要删除edittext默认样式我想删除edittext焦点两侧或普通edittext上的选定部分我只想在普通edittext上使用简单的黑线,在焦点上使用蓝线

我创建了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

在drawable文件夹中创建新的xml文件。 比方说

a、 xml
在drawable文件夹中创建新的xml文件。 比方说

a、 xml
在应用程序主题中为
style.xml
使用定义编辑文本颜色的属性,这些文本是
colorControlActivated
colorControlHighlight
colorControlNormal

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">@color/blackColor</item>
    <item name="colorControlActivated">@color/blueColor</item>
    <item name="colorControlHighlight">@color/blueColor</item>
</style>

@颜色/黑色
@颜色/蓝色
@颜色/蓝色

在应用程序主题中为
style.xml
使用定义编辑文本颜色的属性,这些文本是
colorControlActivated
colorControlHighlight
colorControlNormal

<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorControlNormal">@color/blackColor</item>
    <item name="colorControlActivated">@color/blueColor</item>
    <item name="colorControlHighlight">@color/blueColor</item>
</style>

@颜色/黑色
@颜色/蓝色
@颜色/蓝色

对不同的
编辑文本
状态使用
选择器

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

您的可拉延样品应为Jayanth样品:

<?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>

对不同的
编辑文本
状态使用
选择器

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

您的可拉延样品应为Jayanth样品:

<?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>

尝试以下代码:

编辑_text.xml

<EditText
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/edit_text"
        android:background="@drawable/custom_edit_text_black_line"
 />
请尝试以下代码:

编辑_text.xml

<EditText
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/edit_text"
        android:background="@drawable/custom_edit_text_black_line"
 />

我还想在focus上更改此颜色,我们可以在android中添加:drawableRight吗?我的意思是android的底线:drawableRight???@android要实现这一点,你需要在内部添加另一个,如下图所示,告诉我是否有用:)我还想更改焦点的颜色,我们可以添加android:drawableRight吗?我的意思是android的底线:drawableRight???@android要实现这一点,你需要在内部添加另一个,如下图所示,告诉我是否有用:)