gpt4 book ai didi

android - 设置默认(未聚焦)TextInputLayout 提示 textSize

转载 作者:行者123 更新时间:2023-11-29 16:29:41 25 4
gpt4 key购买 nike

我正在尝试以编程方式更改提示文本大小,但我就是找不到正确的方法。我正在使用 setHintTextAppearance,就像它在示例中显示的那样,但它仅在输入集中或填充了一些数据时才起作用。我也尝试设置 EditText textSize,但仍然没有成功。

textInputLayout.setHintTextAppearance(Vabaco_TextInputLayout_hint_small);
EditText a = textInputLayout.getEditText();
a.setTextSize(8);

最佳答案

您可以像这样使用反射在未聚焦时更改提示文本大小;

 try {
Field filed = TextInputLayout.class.getDeclaredField("mCollapsingTextHelper");
filed.setAccessible(true);
Object helper = filed.get(textInputLayout);

Field f1 = helper.getClass().getDeclaredField("mExpandedTextSize");
f1.setAccessible(true);

f1.set(helper,100);
}
catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}

mExpandedTextSize 的名称可能会根据 TextInputLayout 的依赖版本而有所不同。您应该检查 TextInputLayout 和 CollapsingTextHelper 类以获取变量名称。

希望对你有帮助。

关于android - 设置默认(未聚焦)TextInputLayout 提示 textSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57317427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com