66import android .view .LayoutInflater ;
77import android .view .View ;
88import android .view .ViewGroup ;
9+ import android .widget .ImageView ;
910import android .widget .LinearLayout ;
1011import android .widget .TextView ;
1112
@@ -22,8 +23,8 @@ public class TitleBar extends LinearLayout {
2223 /**
2324 * UI元素
2425 */
25- private TextView mLeftText ;
26- private TextView mRightText ;
26+ private ImageView mLeftBtn ;
27+ private ImageView mRightBtn ;
2728 private TextView mTitleText ;
2829
2930 public TitleBar (Context context , AttributeSet attrs , int defStyle ) {
@@ -32,20 +33,18 @@ public TitleBar(Context context, AttributeSet attrs, int defStyle) {
3233 }
3334
3435 public TitleBar (Context context , AttributeSet attrs ) {
35- super (context , attrs );
36- initUI (context );
36+ this (context , attrs , 0 );
3737 }
3838
3939 public TitleBar (Context context ) {
40- super (context );
41- initUI (context );
40+ this (context , null , 0 );
4241 }
4342
4443 private void initUI (Context ctx ) {
4544 LayoutInflater .from (ctx ).inflate (R .layout .layout_common_title_bar , this );
4645
47- mLeftText = (TextView ) findViewById (R .id .left_text );
48- mRightText = (TextView ) findViewById (R .id .right_text );
46+ mLeftBtn = (ImageView ) findViewById (R .id .left_text );
47+ mRightBtn = (ImageView ) findViewById (R .id .right_text );
4948 mTitleText = (TextView ) findViewById (R .id .title_text );
5049 setStatusBarVisible (BaseActivity .getTopActivity ().isStatusBarTranslate ());
5150 }
@@ -67,14 +66,14 @@ private void setStatusBarVisible(boolean visible) {
6766 * @param l
6867 */
6968 public void setLeftListener (OnClickListener l ) {
70- mLeftText .setOnClickListener (l );
69+ mLeftBtn .setOnClickListener (l );
7170 }
7271
7372 /**
7473 * 设置左边按钮的显示 默认是显示
7574 */
7675 public void setLeftImageVisible (int visible ) {
77- mLeftText .setVisibility (visible );
76+ mLeftBtn .setVisibility (visible );
7877 }
7978
8079 /**
@@ -83,7 +82,7 @@ public void setLeftImageVisible(int visible) {
8382 * @param resourceID
8483 */
8584 public void setLeftImageResource (int resourceID ) {
86- mLeftText . setBackgroundResource (resourceID );
85+ mLeftBtn . setImageResource (resourceID );
8786 }
8887
8988 /**
@@ -92,14 +91,14 @@ public void setLeftImageResource(int resourceID) {
9291 * @param l
9392 */
9493 public void setRightListener (OnClickListener l ) {
95- mRightText .setOnClickListener (l );
94+ mRightBtn .setOnClickListener (l );
9695 }
9796
9897 /**
9998 * 设置左边按钮的显示 默认不显示
10099 */
101100 public void setRightImageVisible (int visible ) {
102- mRightText .setVisibility (visible );
101+ mRightBtn .setVisibility (visible );
103102 }
104103
105104 /**
@@ -108,7 +107,7 @@ public void setRightImageVisible(int visible) {
108107 * @param resourceID
109108 */
110109 public void setRightImageResource (int resourceID ) {
111- mRightText . setBackgroundResource (resourceID );
110+ mRightBtn . setImageResource (resourceID );
112111 }
113112
114113 /**
@@ -149,16 +148,16 @@ public void setTitleTextColor(int color) {
149148 *
150149 * @return
151150 */
152- public TextView getRightButton () {
153- return mRightText ;
151+ public ImageView getRightButton () {
152+ return mRightBtn ;
154153 }
155154
156155 /**
157156 * 获取左边按钮
158157 *
159158 * @return
160159 */
161- public TextView getLeftButton () {
162- return mLeftText ;
160+ public ImageView getLeftButton () {
161+ return mLeftBtn ;
163162 }
164163}
0 commit comments