LoginSignup
3
1

More than 5 years have passed since last update.

RemoteViewsでTextSize変更

Last updated at Posted at 2016-08-23

はじめに

androidのウィジェット作ろうとした時に嵌りかけて、どこにもまとまった解決法が無かったのでメモします

.setTextViewTextSize

通常のTextViewのTextSizeを変更したい場合はこのようにセットできます。

TextView textView;

textView.setTextSize(float size);

しかし、RemoteViewsの場合は下記のようにいろいろ指定しないと動きません。

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout);

remoteViews.setTextViewTextSize(int viewId, int units, float size);

この中で特に分かりにくかったのがunitsの要素です。

unitsとは何なのか

googleのReferenceでは
units int: The units of size (e.g. COMPLEX_UNIT_SP)

とされており、
どうやらTextSizeの単位(dp,sp,px...)を指定できるみたいでした。

単位 units
dip/dp TypedValue.COMPLEX_UNIT_DIP
sp TypedValue.COMPLEX_UNIT_SP
px TypedValue.COMPLEX_UNIT_PX

id:test_textviewのTextSizeを40dpにしたいとき
java
remoteViews.setTextViewTextSize(R.id.test_textview, TypedValue.COMPLEX_UNIT_DIP, 40);

おわりに

これメモっとかないとアカン気がした

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1