+-
android – 从AttributeSet获取提示属性值
我已经覆盖了 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){...}

我该怎么做呢?

最佳答案
您可以通过在视图构造函数中执行以下操作来访问标准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");

如果您的视图继承自TextView并不重要,如果您使用android指定提示:提示它将在您的自定义视图中可访问.

点击查看更多相关文章

转载注明原文:android – 从AttributeSet获取提示属性值 - 乐贴网