版本已更新至1.7.0,最新功能請(qǐng)查看傳送門:
https://github.com/leonHua/LSettingView
在APP開發(fā)中,幾乎每個(gè)應(yīng)用都會(huì)有設(shè)置界面。而設(shè)置界面每一個(gè)條目基本上樣式也都是固定的。每次要么去重新寫布局太浪費(fèi)時(shí)間,要么就是拷貝布局改動(dòng)又太繁瑣串远,所以將每個(gè)條目封裝起來,方便快速實(shí)現(xiàn)儿惫。
設(shè)置界面條目封裝抑淫,同時(shí)包含:
- 設(shè)置左側(cè)圖標(biāo)
- 設(shè)置左側(cè)文字
- 設(shè)置右側(cè)圖標(biāo)
- 設(shè)置右側(cè)圖標(biāo)是否顯示
- 設(shè)置右側(cè)為復(fù)選框樣式
- 設(shè)置右側(cè)為開關(guān)模式
- 設(shè)置右側(cè)文字及樣式
新增設(shè)置
- 設(shè)置左側(cè)圖標(biāo)大小
- 設(shè)置左側(cè)圖標(biāo)和文字間距
- 代碼動(dòng)態(tài)更改左側(cè)文字
- 代碼動(dòng)態(tài)更改右側(cè)文字
- 復(fù)選框和切換按鈕模式下增加選中狀態(tài)監(jiān)聽
-左側(cè)圖標(biāo)默認(rèn)不顯示
-文字大小統(tǒng)一設(shè)置為float格式
-屬性文字(textSize)和顏色(textColor)改成:LtextSize 和 LtextColor,避免和系統(tǒng)沖突
運(yùn)行效果:
效果1
效果2
效果3
效果4
效果5
效果6
快速使用
1. 添加依賴
compile 'com.leon:lsettingviewlibrary:1.4.0'
2. 在布局文件中引用
<com.leon.lib.settingview.LSettingItem
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/item_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
leon:leftIcon="@drawable/history"
leon:leftText="我的消息"/>
3. 添加單擊事件處理
LSettingItem mSettingItemOne = (LSettingItem) findViewById(R.id.item_one);
mSettingItemOne.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {
@Override
public void click(boolean isChecked) {
Toast.makeText(getApplicationContext(), "我的消息", Toast.LENGTH_SHORT).show();
}
});
//更改左側(cè)文字
mSettingItemOne.setLeftText("左側(cè)文字");
//更改右側(cè)文字
mSettingItemOne.setRightText("右側(cè)文字");
自定義屬性
方法說明
屬性 | 說明 | 類型 |
---|---|---|
leftText | 左側(cè)文字 | string |
leftIcon | 左側(cè)圖標(biāo) | integer |
rightIcon | 右側(cè)圖標(biāo) | integer |
textSize | 左側(cè)文字大小 | dimension |
textColor | 左側(cè)文字顏色 | color |
isShowUnderLine | 是否顯示底部分割線 | boolean |
rightStyle | 右側(cè)圖標(biāo)風(fēng)格 | enum |
isShowRightText | 是否顯示右側(cè)文字 | boolean |
rightText | 右側(cè)文字 | string |
rightTextSize | 右側(cè)文字大小 | boolean |
rightTextColor | 右側(cè)文字顏色 | color |
leftIconSize | 左側(cè)圖標(biāo)大小 | dimension |
leftTextMarginLeft | 左側(cè)圖標(biāo)與文字間距 | dimension |
右側(cè)圖標(biāo)風(fēng)格
- iconShow 顯示圖標(biāo)
- iconHide 隱藏圖標(biāo)
- iconCheck 顯示復(fù)選框
- iconSwitch 顯示切換開關(guān)
如果本庫(kù)對(duì)你有用姥闪,歡迎star或者fork! 歡迎訪問 博客 查看更多文章始苇。