Android switchCompat. 和 Switch
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Android  switchCompat. 和 Switch
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                今天禮拜日,回顧知識點 看到了switchCompat?
這里記錄下它的簡單使用
switchCompat? 使用需要導入v7包,一般這個創建項目的時候默認的都用,也就不用關心了
使用呢也很簡單
布局
   <Switchandroid:id="@+id/sw"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="true" /><android.support.v7.widget.SwitchCompatandroid:id="@+id/sc"android:layout_width="wrap_content"android:layout_height="wrap_content"android:checked="false"app:theme="@style/SwitchCompat"/>   <style name="SwitchCompat"><item name="colorControlActivated">#00d</item><item name="colorSwitchThumbNormal">#00d8a0</item><item name="android:colorForeground">#d2f</item></style>style 改變下默認的背景以及按鈕的顏色,
如果想改版圖片可以使用thumb 屬性?
SwitchCompat 和 Switch 使用起來差不多
SwitchCompat 個人感覺使用起來比較好點,
說下它的監聽事件
?
   switchCompat =findViewById(R.id.sc);
//        switchCompat.setChecked(true);//代碼中控制是否代碼
//        switchCompat.setEnabled(true);//設置是否可以點擊switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {if(switchCompat.isChecked()){Toast.makeText(MainActivity.this, "打開了", Toast.LENGTH_SHORT).show();}else{Toast.makeText(MainActivity.this, "關閉了", Toast.LENGTH_SHORT).show();}}});?
總結
以上是生活随笔為你收集整理的Android switchCompat. 和 Switch的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: android studio gradl
- 下一篇: 汽车一般换一次机油多少钱啊?
