Android 在xml和java代码中设置控件的style

306 阅读1分钟
  1. 增加style定义
<style name="myTextStyle">
    <item name="android:textStyle">bold</item>
    <item name="android:textSize">16sp</item>
</style>
  1. XML文件中使用
<TextView 
	style="@style/text_style"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
</TextView>
  1. Java代码中使用(API需要大于等于23)
TextView.setTextAppearance(this, R.style.myTextStyle);

安卓开发技术分享: blog.csdn.net/yinxing2008…