Home > Net >  How to setTextSize (TextView) in dp using RemoteViews
How to setTextSize (TextView) in dp using RemoteViews

Time:07-25

RemoteViews allow me to setTextSize TextView like this:

views.setFloat(R.id.appwidget_text, "setTextSize", fontSize);

but only with one argument. It will set font size in sp. I dont want the text in my widget to be measured in sp. I need use setTextSize with 2 arguments (txtView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize);) using remote views. Is it possible to do this?

CodePudding user response:

Yes! you can use this

public void setTextViewTextSize (int viewId, 
                int units, 
                float size)

viewId int: The id of the view whose text size should change
units int: The units of size (e.g. COMPLEX_UNIT_SP)
size float: The size of the text

This method is only available since API level 16 (android 4.1)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
   remoteViews.setTextViewTextSize(R.id.price, TypedValue.COMPLEX_UNIT_PX, 100f);
}

doc here: https://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewTextSize(int, int, float)

  • Related