android自定义组合控件

创建一个viewgroup

public class KapCustomNextButton extends FrameLayout {

    public KapCustomNextButton(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        View view = LayoutInflater.from(context).inflate(R.layout.view_custom_nextbutton,this);
        ButterKnife.bind(this,view);
    }
}

创建.xml(view_custom_nextbutton.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
</LinearLayout>

创建自定义属性属性(res/value/attrs.xml 中KapCustomNextButton)

<resources>
    <declare-styleable name="KapCustomNextButton">
        <attr name="custon_nextbutton_title_normal" format="string|reference"/>
        <attr name="custon_nextbutton_title_selected" format="string|reference"/>
        <attr name="custon_nextbutton_title_unenable" format="string|reference"/>

        <attr name="custon_nextbutton_titlecolor_normal" format="color|reference"/>
        <attr name="custon_nextbutton_titlecolor_selected" format="color|reference"/>
        <attr name="custon_nextbutton_titlecolor_unenable" format="color|reference"/>

        <attr name="custon_nextbutton_backcolor_normal" format="color|reference"/>
        <attr name="custon_nextbutton_backcolor_selected" format="color|reference"/>
        <attr name="custon_nextbutton_backcolor_unenable" format="color|reference"/>
    </declare-styleable>
</resources>
以上就是全部步骤
以下是细节:
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容