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」; –