gpt4 book ai didi

android - 从 AttributeSet 获取提示属性值

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:11 25 4
gpt4 key购买 nike

我已经覆盖了 this link 中给出的 EditText .

现在在我正在使用的布局中声明这个字段

<com.and.ab1209.ClearableEditText
android:id=”@+id/edit_text_clearable”
android:layout_width=”fill_parent”
android:hint="My Hint Goes here"
android:layout_height=”wrap_content” />

我如何在任何这些构造函数中检索此提示值。

 public ClearableEditText(Context context, AttributeSet attrs, int defStyle){...}
public ClearableEditText(Context context, AttributeSet attrs){...}

我该怎么做?

最佳答案

您可以通过在 View 构造函数中执行以下操作来访问标准 xml 属性:

final String xmlns="http://schemas.android.com/apk/res/android";
//If you had a background attribute this is the resource id
int backgroundResource = attrs.getAttributeResourceValue(xmlns, "background", -1);
//This is your views hint
String hint = attrs.getAttributeValue(xmlns, "hint");

如果您的 View 继承自 TextView 并不重要,如果您使用 android:hint 指定一个提示,它将可以在您的自定义 View 中访问。

关于android - 从 AttributeSet 获取提示属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13509671/

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