Get android:padding attribute programmatically

前端 未结 3 1581

From a view, how can I get the value of the android:padding attribute programmatically? I am currently using:

private static final String ANDROID_NAMESPACE = \"h         


        
3条回答
  •  难免孤独
    2021-02-07 06:37

    You can just add the android:padding to your custom view's attributes.

    
        ...
        
        ...
    
    

    And then, you can access the attribute just like your other attributes:

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActivityWrapperView);
    float padding = a.getDimension(R.styleable.ActivityWrapperView_android_padding, 0);
    ...
    boolean hasPadding = a.hasValue(R.styleable.ActivityWrapperView_android_padding);
    

提交回复
热议问题