Java settextearance()不';我不能在安卓上工作
我曾尝试在Java settextearance()不';我不能在安卓上工作,java,android,Java,Android,我曾尝试在RadioButton中以编程方式设置文本样式,但它们只设置大小和颜色。但如果我通过XML设置样式,它就可以正常工作。我尝试在TextView相同的情况下设置样式。我做错了什么 Java代码: public class YourProgOneApps extends Activity implements OnClickListener { RadioGroup radioGender, radioTarget, radioWhere; RadioButton man, woman,
RadioButton
中以编程方式设置文本样式,但它们只设置大小和颜色。但如果我通过XML设置样式,它就可以正常工作。我尝试在TextView
相同的情况下设置样式。我做错了什么
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>
匹配父项
包装内容
1.
@可牵引/收音机右
@空的
#B4
20便士
#ffffff
1.
1.
1.
水平中心
如果您在UI线程上,请尝试调用invalidate();如果您不在UI线程上,请尝试调用postInvalidate()
在您的示例中,您似乎处于UI线程上,因此请尝试在该textview上调用Invalidate
这将迫使它重新绘制,尽管我认为setTextAppearance会自动执行此操作,但值得一试。我在文档中注意到TextAppearance有点缺少您使用的方法。你能参考一下你正在使用的Android版本吗?2.3.3. 日食时。但这里没有提到2020年的同一问题的弃用方法…(注意:在我的例子中,实际上不起作用的是设置主题,其中包括
colorControlNormal
等属性。普通文本样式,如文本颜色工程)