0
我想使用setTextAppearance更改按钮的样式,但抛出“depreciated”.how以正确使用setTextAppearance?以编程方式更改api小于23的样式
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="button_custom" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">#FFF59D</item>
<item name="colorButtonNormal">#FFF59D</item>
</style>
</resources>
而且活动
公共类MainActivity扩展AppCompatActivity {
Button btn;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
context = this;
btn.setTextAppearance(context,R.style.button_custom);
}
public void setTextAppearance(Context context, int resId) {
if (Build.VERSION.SDK_INT < 23) {
super.setTextAppearance(context, resId);
}
else { super.setTextAppearance(resId);
}
}
}
btn.setTextAppearance(resid)不适用于API小于23.我检查d但是我无法找到答案。 –
我更新了我的答案部分。你可以使用它,看看它是否有帮助 –
我尝试使用AppCompatButton并在setTextAppearance(context,resId)上说“depreciated”; –