分段控件和兩個開關控件實例

switchButton
如何使用

該項目中包含三個控件:SegmentView(分段控件)、倆個開關控件(SwitchView、switchButton)

SegmentView使用:

<com.qiao.commonview.SegmentView
        android:id="@+id/segmentView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        app:content="左邊,中間,右邊"
        app:index="1"
        app:textColorN="#0072c6"
        app:textColorP="#ffffff" />

SegmentView segmentView = (SegmentView)this.findViewById(R.id.segmentView);
segmentView.setOnIndexChangedListener(new OnIndexChangedListener(){

            @Override
            public void onChanged(SegmentView view, int index) {
                Toast.makeText(MainActivity.this, ""+index, Toast.LENGTH_SHORT).show();
            }

        });

SwitchView使用:

<com.qiao.commonview.SwitchView
            android:id="@+id/switchView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:layout_margin="20dp" />

SwitchView switchView = (SwitchView)this.findViewById(R.id.switchView);
switchView.setOnCheckedChangedListener(new OnCheckedChangedListener(){

            @Override
            public void onChanged(View view, boolean checked) {
                Toast.makeText(MainActivity.this, ""+checked, Toast.LENGTH_SHORT).show();
            }

        });

switchButton使用:

<com.qiao.commonview.SwitchButton
            android:id="@+id/switchButton"
            android:layout_width="45dp"
            android:layout_height="25dp"
            android:layout_margin="20dp"
            android:layout_gravity="right|center_vertical"
            app:borderWidth="1px"
            app:offBorderColor="#dadbda"
            app:offColor="#ffffff"
            app:onColor="#4ebb7f"
            app:spotColor="#ffffff"
            app:animate="true" />

SwitchButton switchButton = (SwitchButton)this.findViewById(R.id.switchButton);
switchButton.setOnToggleChanged(new OnToggleChanged(){

            @Override
            public void onToggle(boolean on) {
                Toast.makeText(MainActivity.this, ""+on, Toast.LENGTH_SHORT).show();
            }

        });

demo下載

發佈了47 篇原創文章 · 獲贊 55 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章