android中的标题栏是什么意思,Android通用标题栏组合控件
原標題:Android通用標題欄組合控件
快,點擊藍色“字體”關注這個公眾號,一起漲姿勢
由于項目中經常用到此種組合控件,就封裝了下,具體效果看下圖,老司機可以繞道哈!
一、主要功能
支持左右圖標動態設置
支持左右、中間文字動態修改
支持字體大小、顏色修改
支持左右圖標,左中右文字隱藏顯示
支持左右圖標和文案的點擊監聽
二、基本使用方式
android:id="@+id/customView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:leftImage="@drawable/leftarrow"
app:rightImage="@drawable/rightarrow"
app:leftImageVisiable="true"
app:rightImageVisible="true"
app:leftText="左邊"
app:rightText="右邊"
app:midText="標題"
app:midTextFontColor="#ffffff"
app:leftTextColor="#ffffff"
app:rightTextColor="@color/colorAccent"
app:titleBarBackground="@color/colorPrimary"
app:midTextFontSize="18px"
app:leftTextVisibale="true"
app:rightTextVisible="true"
app:leftTextFontSize="16px"
app:rightTextFontSize="16px"
/>
三、基本屬性介紹
屬性名
屬性說明
屬性值
titleBarBackground
標題欄背景色
color,reference,默認為white
leftImage
左邊圖片
reference
leftImageVisiable
左邊圖片是否可見
boolean,默認為true,顯示控件
leftText
左邊文案
string,reference
leftTextVisibale
左邊文案是否可見
boolean,默認為true,顯示控件
leftTextFontSize
左邊文案字體大小
dimension,reference,默認為16sp
leftTextColor
左邊文案字體顏色
color,reference
midText
中間文案
string,reference
midTextVisiable
中間文案是否可見
boolean,默認為true,顯示控件
midTextFontSize
中間文案字體大小
dimension,reference,默認為18sp
midTextFontColor
中間文案字體顏色
color,reference
rightText
右邊文案
color,reference
rightTextVisible
右邊文案是否可見
boolean,默認為true,顯示控件
rightTextFontSize
右邊文案字體大小
dimension,reference,默認為16sp
rightTextColor
右邊文案字體顏色
color,reference
rightImage
右邊圖片
reference
rightImageVisible
右邊圖片是否可見
boolean,默認為true,顯示控件
四、組合控件類
五、attrs.xml
六、組合控件布局(custom_title_bar.xml)
為什么使用merge,因為組合控件已經extends RelativeLayout,如果根布局還是用viewGroup的話,會使布局重復嵌套,影響View的繪制性能;
七、具體使用
CustomNavigatorBar customNavigatorBar = (CustomNavigatorBar) findViewById(R.id.customView);
/**
* 第一種監聽的具體實現
*/
customNavigatorBar.setLeftImageOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"left",Toast.LENGTH_SHORT).show();
}
});
/**
* 第二種監聽的具體實現
*/
customNavigatorBar.addViewClickListener(new CustomNavigatorBar.OnCustomClickListener() {
@Override
public void onClickListener(View rootView) {
switch (rootView.getId()) {
case R.id.right_image:
Toast.makeText(MainActivity.this,"right_image is clicked",Toast.LENGTH_SHORT).show();
break ;
case R.id.left_image:
Toast.makeText(MainActivity.this,"left_image is clicked",Toast.LENGTH_SHORT).show();
break ;
}
}
});
感謝 王露同學投稿,Github地址:
https://github.com/wangluAndroid/CustomNavigatorBar
如有什么問題,敬請提出!歡迎在作者的 Github 給個Star 也可以分享給小伙伴哦; 小編每天都兢兢業業的為整理干貨,支持小編在下方給鼓勵+1,需要投稿與及有疑問的小伙伴可以在下方留言,小編會第一時間與您聯系!
大家都在看
微信不支持外鏈,請點擊原文查看完整文章詳情.返回搜狐,查看更多
責任編輯:
總結
以上是生活随笔為你收集整理的android中的标题栏是什么意思,Android通用标题栏组合控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android+多米音乐+自动播放,an
- 下一篇: android webview tel: