2016-05-19 15 views
2

私はEditTextの下の行の色を変更しようとしています。私のような質問はほとんど見えませんが、何も助けてくれません。これは私のxmlです:EditTextのボトムラインの色を変更するには?

<EditText 
     android:id="@+id/loginEditText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp"   
     android:hint="@string/login" 
     android:theme="@style/EditTextStyle" 
     android:inputType="textPersonName" > 

そして、これは私のスタイルです:

<color name="green">#00FF00</color> 
<color name="thumbColor">#66aaaaaa</color> 
<color name="darkGrey">#888</color> 
<color name="grey">#ccc</color> 
<color name="white">#fff</color> 
<color name="lightGrey">#bbb</color> 
<color name="veryMidGrey">#eeeeee</color> 
<color name="veryLightGrey">#efefef</color> 
<color name="transparent">#00000000</color> 
<color name="whiteTransparent">#CCFFFFFF</color> 
<color name="blackTransparent">#CC000000</color> 
<color name="material_blue_800">#1565C0</color> 
<color name="material_blue_500">#2196F3</color> 
<color name="material_blue_400">#42A5F5</color> 
<color name="material_blue_700">#1976D2</color> 
<color name="material_blue_300"> #64B5F6</color> 
<color name="black">#000</color> 

しかし、私の一番下の行は、まだ黒です:

<resources> 
    <style name="Theme.MyTheme" parent="Theme.AppCompat.Light"> 
     <item name="colorPrimary">@color/material_blue_500</item> 
     <item name="colorPrimaryDark">@color/material_blue_700</item> 
     <item name="colorAccent">@color/material_blue_700</item> 
     <item name="colorControlNormal">@color/material_blue_700</item> 
     <!-- Active thumb color & Active track color(30% transparency) --> 
     <item name="colorControlActivated">@color/material_blue_500</item> 
     <!-- Inactive thumb color --> 
     <item name="colorSwitchThumbNormal">@color/lightGrey</item> 
     <!-- Inactive track color(30% transparency) --> 
     <item name="android:colorForeground">@color/grey</item> 
     <item name="android:editTextStyle">@style/EditTextStyle</item> 
     <item name="colorControlNormal">@color/material_blue_400</item> 
     <item name="colorControlActivated">@color/material_blue_700</item> 
     <item name="colorControlHighlight">@color/material_blue_700</item> 

    </style> 

    <style name="EditTextStyle" parent="Widget.AppCompat.EditText"> 
      <item name="colorControlNormal">@color/material_blue_400</item> 
      <item name="colorControlActivated">@color/material_blue_700</item> 
      <item name="colorControlHighlight">@color/material_blue_700</item> 
    </style> 
    </resources> 

これが私の色です。何

enter image description here

?あなたのstyle.xmlで 変更

<style name="Theme.App.Base" parent="Widget.AppCompat.EditText"> 
<item name="colorControlNormal">#c5c5c5</item> 
<item name="colorControlActivated">@color/accent</item> 
<item name="colorControlHighlight">@color/accent</item> 
</style> 
+1

おそらくhttp://stackoverflow.com/questions/26574328/changing-edittext-bottom-line-color-with-appcompat-v7 –

答えて

1

用途:

editText.getBackground().mutate().setColorFilter(getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_ATOP); 

注:getColor()メソッドはAPIレベル23のために推奨されていません

+0

PorterDuffを変数 – Tony

+0

に解決することはできません。あなたは_import android.graphics.PorterDuff; _ – Piyush

0

この回答を試してみてください。したがって、あなたはContextcompatを使用して色を取得する必要があります。

+0

いいえ、まだ黒 の複製。完全なstyles.xmlを提供していただけますか? – Tony

+0

@Tonyこのリファレンスを試してください:http://stackoverflow.com/questions/27151569/change-line-color-of-edittext-android –

+0

@DaminiMehra Gujarati? – Piyush

0

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

     </selector> 

描画可能edit.xmlを作成し、EDITTEXT

アンドロイドにこの描画可能に適用されます。背景= "描画可能/編集@"

今、あなたの一番下の行は

を変更します

9枚のパッチ画像

apptheme_textfield_activated_holo_light apptheme_textfield_activated_holo_light

0

あなたはappcompat-v7:22.1.0+使用Drawable Compatを使用している場合。

この機能を参照してください。

public void tintColorWidget(View view, int color) { 
     Drawable wrappedDrawable = DrawableCompat.wrap(view.getBackground()); 
     DrawableCompat.setTint(wrappedDrawable.mutate(), getResources().getColor(color)); 
     view.setBackgroundDrawable(wrappedDrawable); 
} 

そして、あなたのビューに適用します。

EditText txtView = (EditText) findViewById(R.id.edtCurrency); 
tintColorWidget(txtView, R.color.colorPrimary); 
関連する問題