[英]How do I change TextView font style in a Home screen widget?
如何在主屏幕小部件中的TextView中更改字体样式?
If you mean in runtime, a simple way is: 如果要在运行时中使用,一种简单的方法是:
Text Size 字体大小
yourRemoteView.setFloat(R.id.textview, "setTextSize", 30);
Text Color 文字颜色
yourRemoteView.setInt(R.id.textview, "setTextColor", Color.RED);
Like this: 像这样:
First, define text styles in values/styles.xml
: 首先,在
values/styles.xml
定义文本样式:
<resources>
<style name="AppTheme" parent="android:style/Theme.Light">
....
</style>
<style name="WidgetEntryTitle" parent="style/AppTheme">
<item name="android:textSize">24sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@android:color/black</item>
</style>
<style name="WidgetEntryDate" parent="style/AppTheme">
<item name="android:textSize">20sp</item>
<item name="android:textColor">@android:color/black</item>
</style>
</resources>
Then, use the styles in mywidget_layout.xml
: 然后,使用
mywidget_layout.xml
的样式:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
...>
<TextView style="@style/WidgetEntryTitle"
... />
<TextView style="@style/WidgetEntryDate"
... />
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.