Loading core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -60403,6 +60403,7 @@ package android.widget { method public void setLineBreakStyle(int); method public void setLineBreakWordStyle(int); method public void setLineHeight(@IntRange(from=0) @Px int); method public void setLineHeight(int, @FloatRange(from=0) float); method public void setLineSpacing(float, float); method public void setLines(int); method public final void setLinkTextColor(@ColorInt int); core/java/android/widget/TextView.java +33 −3 Original line number Diff line number Diff line Loading @@ -4604,7 +4604,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } private void setTextSizeInternal(int unit, float size, boolean shouldRequestLayout) { @NonNull private DisplayMetrics getDisplayMetricsOrSystem() { Context c = getContext(); Resources r; Loading @@ -4614,8 +4615,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener r = c.getResources(); } return r.getDisplayMetrics(); } private void setTextSizeInternal(int unit, float size, boolean shouldRequestLayout) { mTextSizeUnit = unit; setRawTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()), setRawTextSize(TypedValue.applyDimension(unit, size, getDisplayMetricsOrSystem()), shouldRequestLayout); } Loading Loading @@ -6197,16 +6202,41 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ @android.view.RemotableViewMethod public void setLineHeight(@Px @IntRange(from = 0) int lineHeight) { Preconditions.checkArgumentNonnegative(lineHeight); setLineHeightPx(lineHeight); } private void setLineHeightPx(@Px @FloatRange(from = 0) float lineHeight) { Preconditions.checkArgumentNonnegative((int) lineHeight); final int fontHeight = getPaint().getFontMetricsInt(null); // Make sure we don't setLineSpacing if it's not needed to avoid unnecessary redraw. // TODO(b/274974975): should this also check if lineSpacing needs to change? if (lineHeight != fontHeight) { // Set lineSpacingExtra by the difference of lineSpacing with lineHeight setLineSpacing(lineHeight - fontHeight, 1f); } } /** * Sets an explicit line height to a given unit and value for this TextView. This is equivalent * to the vertical distance between subsequent baselines in the TextView. See {@link * TypedValue} for the possible dimension units. * * @param unit The desired dimension unit. SP units are strongly recommended so that line height * stays proportional to the text size when fonts are scaled up for accessibility. * @param lineHeight The desired line height in the given units. * * @see #setLineSpacing(float, float) * @see #getLineSpacingExtra() * * @attr ref android.R.styleable#TextView_lineHeight */ @android.view.RemotableViewMethod public void setLineHeight(int unit, @FloatRange(from = 0) float lineHeight) { setLineHeightPx( TypedValue.applyDimension(unit, lineHeight, getDisplayMetricsOrSystem())); } /** * Set Highlights * Loading Loading
core/api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -60403,6 +60403,7 @@ package android.widget { method public void setLineBreakStyle(int); method public void setLineBreakWordStyle(int); method public void setLineHeight(@IntRange(from=0) @Px int); method public void setLineHeight(int, @FloatRange(from=0) float); method public void setLineSpacing(float, float); method public void setLines(int); method public final void setLinkTextColor(@ColorInt int);
core/java/android/widget/TextView.java +33 −3 Original line number Diff line number Diff line Loading @@ -4604,7 +4604,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } private void setTextSizeInternal(int unit, float size, boolean shouldRequestLayout) { @NonNull private DisplayMetrics getDisplayMetricsOrSystem() { Context c = getContext(); Resources r; Loading @@ -4614,8 +4615,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener r = c.getResources(); } return r.getDisplayMetrics(); } private void setTextSizeInternal(int unit, float size, boolean shouldRequestLayout) { mTextSizeUnit = unit; setRawTextSize(TypedValue.applyDimension(unit, size, r.getDisplayMetrics()), setRawTextSize(TypedValue.applyDimension(unit, size, getDisplayMetricsOrSystem()), shouldRequestLayout); } Loading Loading @@ -6197,16 +6202,41 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ @android.view.RemotableViewMethod public void setLineHeight(@Px @IntRange(from = 0) int lineHeight) { Preconditions.checkArgumentNonnegative(lineHeight); setLineHeightPx(lineHeight); } private void setLineHeightPx(@Px @FloatRange(from = 0) float lineHeight) { Preconditions.checkArgumentNonnegative((int) lineHeight); final int fontHeight = getPaint().getFontMetricsInt(null); // Make sure we don't setLineSpacing if it's not needed to avoid unnecessary redraw. // TODO(b/274974975): should this also check if lineSpacing needs to change? if (lineHeight != fontHeight) { // Set lineSpacingExtra by the difference of lineSpacing with lineHeight setLineSpacing(lineHeight - fontHeight, 1f); } } /** * Sets an explicit line height to a given unit and value for this TextView. This is equivalent * to the vertical distance between subsequent baselines in the TextView. See {@link * TypedValue} for the possible dimension units. * * @param unit The desired dimension unit. SP units are strongly recommended so that line height * stays proportional to the text size when fonts are scaled up for accessibility. * @param lineHeight The desired line height in the given units. * * @see #setLineSpacing(float, float) * @see #getLineSpacingExtra() * * @attr ref android.R.styleable#TextView_lineHeight */ @android.view.RemotableViewMethod public void setLineHeight(int unit, @FloatRange(from = 0) float lineHeight) { setLineHeightPx( TypedValue.applyDimension(unit, lineHeight, getDisplayMetricsOrSystem())); } /** * Set Highlights * Loading