How do I change TextView font style in a Home screen widget?

早过忘川 提交于 2019-12-22 13:50:33

问题


How do I change the font style in a TextView in a Home screen widget?


回答1:


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);



回答2:


Like this:

First, define text styles in 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:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    ...>

    <TextView style="@style/WidgetEntryTitle"
        ... />

    <TextView style="@style/WidgetEntryDate"
        ... />
</RelativeLayout>


来源:https://stackoverflow.com/questions/9599196/how-do-i-change-textview-font-style-in-a-home-screen-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!