public class JoTabLayout extends TabLayout {
public JoTabLayout(@NonNull Context context) {
super(context);
}
public JoTabLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public JoTabLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
}
这里讲一下 继承TabLayout 然后给TabLayout 添加自定义属性
我需要给JoTabLayout添加两个自定义的扩展属性
然后需要在class定义中获取
public class JoTabLayout extends TabLayout {
public JoTabLayout(@NonNull Context context) {
super(context);
}
public JoTabLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.handleCustomAttrs(context, attrs);
}
public JoTabLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.handleCustomAttrs(context, attrs);
}
private void handleCustomAttrs(@NonNull Context context, @Nullable AttributeSet attrs) {
//获取自定义属性。
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.JoTabLayout);
ta.getString(R.styleable.JoTabLayout_joTabSelectedTextAppearance);
// 默认tab 自定义 属性
String tabTextAppearance = ta.getString(R.styleable.JoTabLayout_joTabTextAppearance);
System.out.println(tabTextAppearance);
String tabSelectedTextAppearance = ta.getString(R.styleable.JoTabLayout_joTabSelectedTextAppearance);
System.out.println(tabSelectedTextAppearance);
、、、、、
// 具体处理逻辑 根据情况处理
、、、、、
ta.recycle();
}
}
不居中设置