1
我已經嘗試以編程方式在RadioButton
中設置樣式的文本,但它們只設置大小和顏色。但是,如果我通過XML設置風格,它可以正常工作。我嘗試了TextView
同樣的情況。我究竟做錯了什麼?setTextAppearance()在Android上不起作用
Java代碼:
public class YourProgOneApps extends Activity implements OnClickListener {
RadioGroup radioGender, radioTarget, radioWhere;
RadioButton man, woman, build_muscle, fat_loss, keep_in_good_shape, gym, home;
TextView textView2;
Button btnExeProgOne;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_prog1);
radioGender = (RadioGroup) findViewById(R.id.radioGender);
man = (RadioButton) findViewById(R.id.man);
woman = (RadioButton) findViewById(R.id.woman);
textView2 = (TextView) findViewById(R.id.textView2);
textView2.setTextAppearance(getApplicationContext(), R.style.radio_chek_f_pre_f);
man.setTextAppearance(this, R.style.radio_chek_f_pre_f);
radioTarget = (RadioGroup) findViewById(R.id.radioTarget);
radioWhere = (RadioGroup) findViewById(R.id.radioWhere);
}
public void onClick(View v) {}
}
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light" />
<style name="radio_chek_f_pre_f">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:background">@drawable/radio_right</item>
<item name="android:button">@null</item>
<item name="android:textColor">#b4b4b4</item>
<item name="android:textSize">20sp</item>
<item name="android:shadowColor">#ffffff</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">1</item>
<item name="android:gravity">center_horizontal</item>
</style>
</resources>
我在文檔中注意到TextAppearance有點遺漏了使用的方法。你可以參考你使用的Android版本嗎? http://developer.android.com/reference/android/widget/TextView.html#attr_android:textAppearance – Zerkz 2013-02-26 13:06:45
2.3.3。在Eclipse上。但是這裏沒有關於棄用方法[link]的說法(http://developer.android.com/reference/android/widget/TextView.html#setTextAppearance%28android.content.Context,%20int%29) – Roman 2013-02-26 13:11:22