I am trying to read the custom attribute without extending the View. I am following this post:- How to read custom attributes in Android
Is it possible to add this in only one activity? or this is needed to be added whereever the custom attributes are needed to be fetched?
public abstract class BaseDialog extends DialogFragment {
@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getLayoutInflater().setFactory(new CustomAttrFactory());
}
public static class CustomAttrFactory implements LayoutInflater.Factory {
@Override
public View onCreateView(String name, Context context,
AttributeSet attrs) {
String attributeValue = attrs
.getAttributeValue(
"http://schemas.android.com/apk/res-auto",
"stringId");
System.out.println("Attribute obtained using this method/" + attributeValue);
// if attributeValue is non null then you know the attribute is
// present on this view(you can use the name to identify the view,
// or its id attribute)
return null;
}
}
The above implementation is not working for me.