<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/navBarHeight"
android:background="@color/mainColor"
android:paddingLeft="@dimen/marginSize"
android:paddingRight="@dimen/marginSize">
<ImageView
android:id="@+id/iv_back"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="left|center"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="标题"
android:textColor="@android:color/white"
android:textSize="@dimen/narBarTextSize" />
<ImageView
android:id="@+id/iv_me"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="right|center"
android:src="@mipmap/ic_launcher" />
public class BaseActivity extends Activity {
private TextView tvTitleText;
private ImageView mIvBack;
private ImageView mIvMe;
/**
* findViewById
*
* @param id
* @param <T>
* @return
*/
protected <T extends View> T fd(@IdRes int id) {
return findViewById(id);
}
/**
* 初始化navgation
*
* @param isShowBack
* @param titleText
* @param isShowMe
*/
protected void initNavBar(boolean isShowBack, String titleText, boolean isShowMe) {
mIvBack = fd(R.id.iv_back);
tvTitleText = fd(R.id.tv_title);
mIvMe = fd(R.id.iv_me);
mIvBack.setVisibility(isShowBack ? View.VISIBLE : View.GONE);
mIvMe.setVisibility(isShowMe ? View.VISIBLE : View.GONE);
tvTitleText.setText(titleText);
mIvBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
}
}