2013-08-19 4 views
1

Вот мой кодTextColor и textAppearance из EditText

<style name="AppBaseTheme" parent="android:Theme.Light"> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:textAppearance">@style/App_TextAppearance</item> 
    <item name="android:editTextStyle">@style/App_EditTextStyle</item> 
    <item name="android:textViewStyle">@style/App_TextViewStyle</item> 
</style> 

<style name="App_TextAppearance" parent="@android:style/TextAppearance"> 
    <item name="android:textColor">#ffff0000</item> 
</style> 

<style name="App_EditTextStyle" parent="@android:style/Widget.EditText"> 
    <item name="android:textAppearance">?android:textAppearance</item> 
</style> 

<style name="App_TextViewStyle" parent="@android:style/Widget.TextView"> 
    <item name="android:textAppearance">?android:textAppearance</item> 
</style> 

Проблема заключается в том, теперь TextColor всех TextViews являются RED, но TextColor всех edittexts еще черный. Я знаю, что мне нужно установить элемент атрибута android: textColor в App_EditTextStyle, чтобы изменить цвет edittext, но почему? Является ли андроид: textAppearance attr бесполезен для edittext?

+0

Атрибут android: textAppearance должен быть ссылкой на другой ресурс в форме «@ [+] [package:] type: name» или в атрибут темы в форме «? [Package:] [type:] имя". Чтобы изменить цвет отдельного текста, вам нужно будет расширить стиль внешнего вида текста. – Pria

ответ

1

Этот вид изменений я пробовал в коде, а не в части xml. Это может быть достигнуто с помощью onFocusChangeListener EditText.

import android.app.Activity; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnFocusChangeListener; 
import android.widget.EditText; 

public class MainActivity extends Activity { 
/** Called when the activity is first created. */ 

EditText et1; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    et1 = (EditText) findViewById(R.id.editText1);   


    et1.setOnFocusChangeListener(new OnFocusChangeListener() { 

     public void onFocusChange(View v, boolean hasFocus) { 
      if (hasFocus) //Whenever your EditText is focused this color will be applied 
        et1.setTextColor(Color.RED);   
       else //Otherwise display the text in Gray Color 
        et1.setTextColor(Color.GRAY);    
     } 
    }); 

} 
} 

Этот человек работал на меня. Надеюсь, это поможет и вам.