EditText行不可见,不会改变颜色

时间:2017-01-24 10:42:40

标签: android colors android-edittext styles output

所以有一段时间了,我已经尝试解决我在EditText字段中遇到的问题,因为它没有显示提示或实际文本所在的单行。通常,该行默认为黑色,所以我的问题是这个;如何让线条再次显示,以及如何更改线条的颜色? (我会假设android:backgroundHint会做的伎俩然而我根本看不到线路所以无法测试它)。我正在使用API​​ 24/25。

下面是我的XML代码示例以及模拟器输出:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.michael.whatsupldn.RegisterActivity">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">

  <EditText
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="Name"
      android:layout_margin="16dp"/>

</LinearLayout>

</RelativeLayout>

Emulator Output

我的styles.xml代码

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="EditTextTheme">
    <!-- Used for the bottom line when not selected / focused -->
    <item name="colorControlNormal">#FAFAFA</item>
    <!-- colorControlActivated & colorControlHighlight use the colorAccent         color by default -->
</style>

</resources>

我的colors.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorRadioButton">#f5f5f5</color>
    <color name="yellow1">#ffff00</color>
    <color name="yellow2">#ffEA00</color>
    <color name="grey05">#F5F5F5</color>
    <color name="orange4">#FFB74D</color>
    <color name="orange5">#FFA726</color>
    <color name="blue2">#f5f5f5</color>
    <color name="blue25">#fafafa</color>
    <color name="white">#ffffff</color>
</resources>

5 个答案:

答案 0 :(得分:3)

<EditText
    android:id="@+id/editTextAddress"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:textSize="20dp"
    android:inputType="textMultiLine|textCapWords"
    android:background="@drawable/edit_text_bottom_border"
    android:hint="Address">

// edit_text_bottom_border.xml          

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/r...">
    <item
        android:bottom="1dp"
        android:left="-3dp"
        android:right="-3dp"
        android:top="-3dp">
        <shape android:shape="rectangle">
            <stroke
                android:width="2dp"
                android:color="#000" />

            <solid android:color="#00ffffff" />

        </shape>
    </item>
</layer-list>

答案 1 :(得分:3)

backgroundTint白色更改为xml布局文件中edittext中的其他深色,并更改活动的主题

请参阅此链接:http://www.codexpedia.com/android/setting-edittext-underline-color-in-android/

答案 2 :(得分:1)

将高度更改为 wrap_content

<EditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Name"
  android:layout_margin="16dp"/>

答案 3 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_register"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.michael.whatsupldn.RegisterActivity">

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true">
           <EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Underline color change"
    android:backgroundTint="@android:color/holo_red_light" />
            <requestFocus/>
        </EditText>
    </LinearLayout>

</RelativeLayout>

答案 4 :(得分:0)

从布局文件中删除以下行(如果已存在)

for(i=0;i<9215;i+=4)
{                                                                                   
             int32x4_t l_N = vld1q_s32(&L[i]);
            uint32x4_t mask_n=vcltq_s32(l_N,zero_N);
             int32x4_t z_n = vbslq_s32(mask_n,one_N,zero_N);
             vst1q_s32(&Z[i],z_n);

}