2016-11-11 10 views
0

編集テキストのボトムカラーをさまざまな方法で変更しようとしましたが、変更はありません。私はdrawableを使いたくありません。AndroidでEditTextのボトムラインの色を変更するには?

ここは私のxmlで、私が使ってみた方法です。

方法1:

android:backgroundTint="@color/colorPrimary" 

方法2:

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

    <item name="colorControlNormal">@color/colorPrimary</item> 
    <item name="colorControlActivated">@color/colorPrimary</item> 
    <item name="colorControlHighlight">@color/colorPrimary</item> 

</style> 

</resources> 

は、ここに私の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" 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:id="@+id/b" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.isaac.loginexamples.b"> 

<RelativeLayout 
    android:background="#009688" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/relative_half_screen_height"> 
</RelativeLayout> 

<android.support.v7.widget.CardView 
    card_view:cardElevation="18dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:layout_width="@dimen/card_view_width" 
    android:layout_height="@dimen/card_view_height"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <View 
      android:id="@+id/header_logo_two" 
      android:background="#22313F" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/view_header_height"></View> 

     <View 
      android:background="@drawable/shadow" 
      android:layout_below="@+id/header_logo_two" 
      android:layout_width="match_parent" 
      android:layout_height="7dp"></View> 

     <ImageView 
      android:layout_marginTop="25dp" 
      android:layout_centerHorizontal="true" 
      android:id="@+id/logo_two" 
      android:background="@mipmap/ic_launcher" 
      android:layout_width="@dimen/logo_image_width_height" 
      android:layout_height="@dimen/logo_image_width_height" /> 

     <EditText 
      android:backgroundTint="@color/colorPrimary" 
      android:id="@+id/username" 
      android:layout_marginTop="15dp" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@+id/logo_two" 
      android:layout_width="270dp" 
      android:layout_height="45dp" 
      android:inputType="textEmailAddress" /> 

     <EditText 
      android:layout_marginTop="8dp" 
      android:layout_alignLeft="@+id/username" 
      android:layout_below="@+id/username" 
      android:layout_width="240dp" 
      android:layout_height="45dp" /> 

    </RelativeLayout> 

    </android.support.v7.widget.CardView> 

    </RelativeLayout> 

「私は私がオンラインに見てきたこれらの二つの方法を試してみましたが、それはdoesnの仕事。私はAndroid Studioの最新バージョンを実行しています。私は解決策があることを願っています。 注:私はドローイングを使用したくありません。 ありがとうございます!

+0

多分あなたはdrawable xD – Beloo

+0

Maを使うべきですあなたは知っている、私はむしろAppCompatを使用します。私はそれがより素晴らしく、より信頼できると思います。 @Beloo –

答えて

0

あなたが描画可能なを使用したくない場合は、あなたがのEditText下の「ビュー」を使用してのEditTextあなたの活動や断片内

<View 
    android:id="@+id/username_view" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/size_1" 
    android:layout_alignEnd="@+id/username" 
    android:layout_alignLeft="@+id/username" 
    android:layout_alignRight="@+id/username" 
    android:layout_alignStart="@+id/username" 
    android:layout_below="@+id/username" 
    android:background="@color/grey"/> 

のfocuschangeに基づいて、そのViewの色を変更することができますユーザー名のフォーカス変更に基づいて表示の色を変更するこれらのコード行を追加します。

@OnFocusChange(R.id.username) 
void onUserNameFocusChanged(View v, boolean hasFocus) { 
    if (userNameView != null) { 
     int focusViewColor = hasFocus ? getResources().getColor(R.color.red) : getResources().getColor(R.color.grey); 
     userNameView.setBackgroundColor(focusViewColor); 
    } 
} 
+0

@ Tanis.7x編集に感謝します。 – Madhu

関連する問題