2017-01-24 13 views
0

Итак, какое-то время я попытался исправить проблему, с которой я столкнулся, с полем EditText, поскольку она не отображает единственную строку под подсказкой или фактический текст будет идти. Как правило, линия по умолчанию будет черной, поэтому мой вопрос таков; как включить отображение строки снова, а также как изменить ее цвет? (Я бы предположил, что андроид: backgroundHint сделал бы трюк, но я просто не вижу линию вообще, поэтому не могу ее проверить). Я использую API 24/25.Линия EditText не отображается и не меняет цвет

Ниже приведен пример моего кода 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> 
+0

Там нет ничего плохого с кодом, добавить тему код. – W4R10CK

+0

@ W4R10CK Я добавил его – AndroidDevBro

+0

попытаюсь изменить тему из раздела предварительного просмотра. – W4R10CK

ответ

1
<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> 
+0

Если бы у меня было несколько EditText, я бы получил список слоев после каждого из них, например. EditText, LayerList, Edit, Text, LayerList или будет ли LayerList определяться в нижней части страницы XML? – AndroidDevBro

+0

создайте edit_text_bottom_border.xml-файл внутри папки с возможностью перемещения внутри папки res и установить фон edittext, нет необходимости писать код слоя-слоя внутри файла макета. –

1

Изменение высоты в wrap_content

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

Изменение высоты на 'wrap_content' не делает ничего нового, его уже« match_parent », который соответствует родительской высоте. – W4R10CK

+0

@ W4R10CK Да точно, моя высота уже wrap_conent, а width - match_parent. Значение должно отображаться горизонтально, чтобы соответствовать линейной компоновке, но nothin отображает – AndroidDevBro

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> 
+0

К сожалению, это ничего не изменило для меня. – AndroidDevBro

+0

, так что вы можете сказать мне, что на самом деле происходит? –

+0

@ diwn.dhanvani Как я уже объяснял выше, линия, которая должна быть под полем EditText, не отображается – AndroidDevBro