Get textView properties from Android appi level 14

Asked 2 years ago, Updated 2 years ago, 25 views

I am using static Layout

new StaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad)

You should hand over the attributes of the view as follows. The part in question is

spacingmult, spacingadd, includepad This is.

These variables were taken as a function:

getLineSpacingMultiplier(); getLineSpacingExtra(); getIncludeFontPadding();

These functions are supported from api 16 Set the standard of min api level to 14 The function above has been disabled

Is there any other function that works in api 14 to replace the above function?

android

2022-09-21 14:48

1 Answers

The following functions of TextVew you mentioned are supported from API 16, so they are not available in lower versions.

getLineSpacingMultiplier(); 
getLineSpacingExtra(); 
getIncludeFontPadding();

I think we can apply three alternatives depending on the situation.

If the above settings in TextView do not change at runtime, you can use the default values. In Android 4.0, TextView.java you can see that the value is initialized as follows:

private float mSpacingMult = 1.0f;
private float mSpacingAdd = 0.0f;
private boolean mIncludePad = true;

Therefore, when you create Static Layout, you can pass the value as shown below.

new StaticLayout(source, paint, width, align, 1.0f, 0.0f, true);

If the above value is changed at runtime, the value can be read through reflection under API 16. Replaced with links to read specific fields by reflection. (Google to find more information.)

It may be a little far from the solution, but the share of API 16, or ice cream sandwich, in the Android ecosystem is only 4%. My personal opinion is that there will be no problem if I start supporting API 16 unless I have to support the lower version (1.9%) of ice cream sandwiches.

Graph Source


2022-09-21 14:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.