android自定义组合控件

2017-12-01  本文已影响12人  风___________

创建一个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>
以上就是全部步骤
以下是细节:
上一篇 下一篇

猜你喜欢

热点阅读