Crash setTextViewTextSize in a widget only without Jelly Bean
Asked Answered
P

3

8

I am making a widget in which you can specify the text size

controles.setTextViewTextSize(R.id.LblMsg, TypedValue.COMPLEX_UNIT_SP, textSize);

I am working with android 4.1

android:minSdkVersion="8" android:targetSdkVersion="16"

The problem is that it works correctly in android 4.1, but in any other version (ICS, gingerbread, etc) shows a forced close.

java.lang.NoSuchMethodError: android.widget.RemoteViews.setTextViewTextSize

If I remove the line of code where it is used "setTextViewTextSize", the application works perfectly.

I find no information about the reason for this error.

I appreciate any help.

Regards

Petronia answered 28/8, 2012 at 11:22 Comment(0)
D
4

This method is only available since API level 16 (android 4.1) : http://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewTextSize(int, int, float)

Dorey answered 28/8, 2012 at 11:24 Comment(2)
and what is the method that I can use in earlier versions of android? thanksPetronia
Chech this out: #6722116Dorey
J
7

if you wish to use something that works on all versions, use this:

remoteViews.setFloat(R.id.textView,"setTextSize",fontSize);
Jato answered 18/5, 2013 at 23:14 Comment(0)
D
4

This method is only available since API level 16 (android 4.1) : http://developer.android.com/reference/android/widget/RemoteViews.html#setTextViewTextSize(int, int, float)

Dorey answered 28/8, 2012 at 11:24 Comment(2)
and what is the method that I can use in earlier versions of android? thanksPetronia
Chech this out: #6722116Dorey
C
1

I did this

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
   remoteViews.setTextViewTextSize(R.id.price, TypedValue.COMPLEX_UNIT_PX, 100f);
}
Contortionist answered 29/12, 2012 at 1:11 Comment(1)
this solutions works but don't forget that last param is float - so we must use f at the end, it will be like: remoteViews.setTextViewTextSize(R.id.price, TypedValue.COMPLEX_UNIT_PX, 100f);Gunnar

© 2022 - 2024 — McMap. All rights reserved.