自定义视图中使用的样式不会发送给构造函数

时间:2019-09-12 07:01:53

标签: android android-layout

我有一个名为LoadingButton的自定义视图,扩展了FrameLayout。此类是inflatin自定义XML布局,其中包含LinearLayoutProgressBar及其父FrameLayout。这应该用作Button。我为每种Button类型都有自定义定义的样式(更改背景,色调,文本颜色...)。我想将此样式传递到“自定义视图”类中。但它不起作用。不会调用这种类型的构造函数。而是调用具有ContextAttributeSet的总承包商。

有什么解释吗?不过,如果我将样式添加到自定义视图中,则会自动检测到样式,并调用其他类型的构造函数。

构造函数:

@SuppressLint("ClickableViewAccessibility")
    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        parseAttrs(context, attrs)
    }

    @SuppressLint("ClickableViewAccessibility")
    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        parseAttrs(context, attrs, defStyleAttr)
    }

自定义视图的使用:

<com.project.custom.LoadingButton
    android:id="@+id/btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/button_blue_filled"
    app:l_buttonText="@string/text"
    android:layout_marginTop="48dp" />

0 个答案:

没有答案
相关问题