|
@@ -0,0 +1,138 @@
|
|
|
+package com.ynstkz.shitu.android.helper;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.ynstkz.shitu.android.R;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 作者:fuchangle on 2018/1/27 22:28
|
|
|
+ */
|
|
|
+
|
|
|
+public class TitleBarHelper {
|
|
|
+
|
|
|
+ /*上下文,创建view的时候需要用到*/
|
|
|
+ private Context mContext;
|
|
|
+
|
|
|
+ /*base view*/
|
|
|
+ private FrameLayout mContentView;
|
|
|
+
|
|
|
+ /*用户定义的view*/
|
|
|
+ private View mUserView;
|
|
|
+
|
|
|
+ /*视图构造器*/
|
|
|
+ private LayoutInflater mInflater;
|
|
|
+
|
|
|
+ private ImageView iv_back;
|
|
|
+ private TextView barTitle;
|
|
|
+ private TextView tv_title_right;
|
|
|
+ private ImageView ivTitleRight;
|
|
|
+ private RelativeLayout rlBarView;
|
|
|
+
|
|
|
+ public TitleBarHelper(Context context, int layoutId) {
|
|
|
+ this.mContext = context;
|
|
|
+ mInflater = LayoutInflater.from(mContext);
|
|
|
+ /*初始化整个内容*/
|
|
|
+ initContentView();
|
|
|
+ /*初始化用户定义的布局*/
|
|
|
+ initUserView(layoutId);
|
|
|
+ /*初始化titleBar*/
|
|
|
+ initTitleBar();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void initContentView() {
|
|
|
+ /*直接创建一个帧布局,作为视图容器的父容器*/
|
|
|
+ mContentView = new FrameLayout(mContext);
|
|
|
+ ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
+ mContentView.setLayoutParams(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initTitleBar() {
|
|
|
+ /*通过inflater获取toolbar的布局文件*/
|
|
|
+ View titleBar = mInflater.inflate(R.layout.view_titlebar, mContentView);
|
|
|
+ iv_back = titleBar.findViewById(R.id.iv_back);
|
|
|
+ barTitle = titleBar.findViewById(R.id.tv_barTitle);
|
|
|
+ rlBarView = titleBar.findViewById(R.id.rl_bar_view);
|
|
|
+ tv_title_right = titleBar.findViewById(R.id.tv_title_right);
|
|
|
+ ivTitleRight = titleBar.findViewById(R.id.iv_title_right);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initUserView(int id) {
|
|
|
+ mUserView = mInflater.inflate(id, null);
|
|
|
+ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
+ params.topMargin = (int) (mContext.getResources().getDimension(R.dimen.titlebar_height)) - 1;
|
|
|
+ mContentView.addView(mUserView, params);
|
|
|
+ }
|
|
|
+
|
|
|
+ public FrameLayout getContentView() {
|
|
|
+ return mContentView;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置titlebar标题
|
|
|
+ * @param title
|
|
|
+ */
|
|
|
+ public void setBarTitle(String title){
|
|
|
+ barTitle.setText(title);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取返回按钮
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ImageView getBackUpView(){
|
|
|
+ return iv_back;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 右侧字体
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public TextView getTitleRightTxt(){
|
|
|
+ return tv_title_right;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 右侧图片
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ImageView getIvTitleRight() {
|
|
|
+ return ivTitleRight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIvTitleRight(ImageView ivTitleRight) {
|
|
|
+ this.ivTitleRight = ivTitleRight;
|
|
|
+ }
|
|
|
+
|
|
|
+ public RelativeLayout getRlBarView() {
|
|
|
+ return rlBarView;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRlBarView(RelativeLayout rlBarView) {
|
|
|
+ this.rlBarView = rlBarView;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ImageView getIv_back() {
|
|
|
+ return iv_back;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIv_back(ImageView iv_back) {
|
|
|
+ this.iv_back = iv_back;
|
|
|
+ }
|
|
|
+
|
|
|
+ public TextView getBarTitle() {
|
|
|
+ return barTitle;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setBarTitle(TextView barTitle) {
|
|
|
+ this.barTitle = barTitle;
|
|
|
+ }
|
|
|
+}
|