android settext里面的参数,android 更改TextView参数后,给定文本无法应用于TextView - 糯米PHP...

因此,我进行了扩展以在TextView中实现预计算文本。

自从迁移到Material Components Theme以来,我一直遇到错误。

这是下面的代码。

我还尝试了将所有TextViews和AppCompatTextViews迁移到MaterialTextView。但是问题仍然存在。

fun AppCompatTextView.setTextFuture(string: String?) {

val precomputedText =

PrecomputedTextCompat.getTextFuture(

string ?: "",

TextViewCompat.getTextMetricsParams(this),

null

)

textMetricsParamsCompat = precomputedText.get().params

setTextFuture(precomputedText)

text = string

}

fun AppCompatTextView.setTextFuture(charSequence: CharSequence?) {

val precomputedText =

PrecomputedTextCompat.getTextFuture(

charSequence ?: "",

TextViewCompat.getTextMetricsParams(this),

null

)

textMetricsParamsCompat = precomputedText.get().params

setTextFuture(precomputedText)

text = charSequence

}

fun AppCompatTextView.setTextFuture(stringResId: Int) {

val string = context.getString(stringResId)

val precomputedText =

PrecomputedTextCompat.getTextFuture(

string,

TextViewCompat.getTextMetricsParams(this),

null

)

textMetricsParamsCompat = precomputedText.get().params

setTextFuture(precomputedText)

text = string

}

错误如下。

Fatal Exception: java.lang.IllegalArgumentException

Given text can not be applied to TextView.

androidx.core.widget.TextViewCompat.setPrecomputedText (TextViewCompat.java:891)

androidx.appcompat.widget.AppCompatTextView.onMeasure (AppCompatTextView.java:550)

android.view.View.measure (View.java:24953)

Fatal Exception: java.lang.IllegalArgumentException

PrecomputedText's Parameters don't match the parameters of this TextView.Consider using setTextMetricsParams(precomputedText.getParams()) to override the settings of this TextView: PrecomputedText: {textSize=49.0, textScaleX=1.0, textSkewX=0.0, letterSpacing=0.03125, textLocale=[en_GB], typeface=android.graphics.Typeface@5e608edd, variationSettings=null, elegantTextHeight=false, textDir=android.text.TextDirectionHeuristics$TextDirectionHeuristicInternal@eb941bf, breakStrategy=1, hyphenationFrequency=0}TextView: {textSize=49.0, textScaleX=1.0, textSkewX=0.0, letterSpacing=0.03125, textLocale=[en_GB], typeface=android.graphics.Typeface@5e608edd, variationSettings=null, elegantTextHeight=false, textDir=android.text.TextDirectionHeuristics$TextDirectionHeuristicInternal@eb941bf, breakStrategy=1, hyphenationFrequency=0}

android.widget.TextView.setText (TextView.java:6724)

Fatal Exception: java.lang.IllegalArgumentException

PrecomputedText's Parameters don't match the parameters of this TextView.Consider using setTextMetricsParams(precomputedText.getParams()) to override the settings of this TextView: PrecomputedText: {textSize=70.0, textScaleX=1.0, textSkewX=0.0, letterSpacing=0.03125, textLocale=[en_CA], typeface=android.graphics.Typeface@ab2ab1bb, variationSettings=null, elegantTextHeight=false, textDir=android.text.TextDirectionHeuristics$TextDirectionHeuristicInternal@34fe469, breakStrategy=1, hyphenationFrequency=0}TextView: {textSize=70.0, textScaleX=1.0, textSkewX=0.0, letterSpacing=0.03125, textLocale=[en_CA], typeface=android.graphics.Typeface@ab2ab1bb, variationSettings=null, elegantTextHeight=false, textDir=android.text.TextDirectionHeuristics$TextDirectionHeuristicInternal@34fe469, breakStrategy=1, hyphenationFrequency=0}

android.widget.TextView.setText (TextView.java:6731)

我的某些TextView具有这些属性

android:ellipSize="marquee"

android:singleLine="true"

isSelected = true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值