android 标题栏高度工具类,购物直播系统Android—标题栏工具类

/**

* 一个自定义的通用标题栏实列类

*/

public class CustomeTitleBar extends RelativeLayout {

/**

* 上下文

*/

private Context mContext;

/**

* 左边文字

*/

private TextView left_tx = null;

/**

* 左图片

*/

private ImageView left_img = null;

/**

* 左边按钮

*/

private RelativeLayout left_rl = null;

/**

* 中间标题文本

*/

private TextView center_tx = null;

/**

* 右通用文本

*/

private TextView right_tx = null;

/**

* 右图片

*/

private ImageView right_img = null;

/**

* 右按钮

*/

private RelativeLayout right_rl = null;

/**

* title整体布局

*/

private RelativeLayout title_rl = null;

/**

*

* 填充状态栏

*/

private View view_status_bar_place=null;

/*

* 主布局

*

*/

private LinearLayout title_main_view;

public LinearLayout getTitle_main_view() {

return title_main_view;

}

public CustomeTitleBar(Context context) {

this(context, null);

}

public CustomeTitleBar(final Context context, AttributeSet attrs) {

super(context, attrs);

initViews(context,attrs);

initListeners();

}

/**

* 初始化UI组件.

*/

public void initViews(Context context, AttributeSet attrs) {

//如果在自定义控件的构造函数或者其他绘制相关地方使用系统依赖的代码,会导致可视化编辑器无法报错并提示:Use View.isInEditMode() in your custom views to skip code when shownin Eclipse

if (isInEditMode()) {

return;

}

this.mContext=context;

LayoutInflater.from(this.getContext()).inflate(R.layout.include_custometitlebar

, this, true);

left_tx = (TextView) this.findViewById(R.id.left_tx);

left_img = (ImageView) this.findViewById(R.id.left_img);

left_rl = (RelativeLayout) this.findViewById(R.id.left_rl);

center_tx = (TextView) this.findViewById(R.id.center_tx);

right_tx = (TextView) this.findViewById(R.id.right_tx);

right_img = (ImageView) this.findViewById(R.id.right_img);

right_rl = (RelativeLayout) this.findViewById(R.id.right_rl);

title_rl = (RelativeLayout) this.findViewById(R.id.title_rl);

title_main_view = (LinearLayout) this.findViewById(R.id.title_main_view);

view_status_bar_place=this.findViewById(R.id.view_status_bar_place);

//默认右边的这个操作按钮是隐藏的  和左边的文字是隐藏的

right_rl.setVisibility(View.GONE);

left_tx.setVisibility(View.GONE);

initAttrs(attrs);

}

/**

* 初始化attrs

* @param attrs

*/

private void initAttrs(AttributeSet attrs) {

//获取attr属性

TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.CustomeTitleBar);

//右边图标

int rightIcon = typedArray.getResourceId(R.styleable.CustomeTitleBar_rightIcon, 0);

//中间文字

int centerTitle = typedArray.getResourceId(R.styleable.CustomeTitleBar_centerText,0);

//右边文字

int rightTitle = typedArray.getResourceId(R.styleable.CustomeTitleBar_rightText,0);

if(rightIcon!=0){

//右边图标

right_img.setImageResource(rightIcon);

}

if(centerTitle!=0){

//中间文字

center_tx.setText(centerTitle);

}

if(rightTitle!=0){

//右边文字

right_tx.setText(rightTitle);

right_rl.setVisibility(View.VISIBLE);

}

}

/**

* 后退监听事件

*/

public void initListeners()

{

left_rl.setOnClickListener(new OnClickListener(){

@Override

public void onClick(View v)

{

fireBack();

}

});

}

/**

* 点击返回按钮要调用的方法

*/

public void fireBack()

{

if(this.getContext() instanceof Activity)

((Activity)this.getContext()).finish();

}

public TextView getLeft_tx() {

return left_tx;

}

public ImageView getLeft_img() {

return left_img;

}

public RelativeLayout getLeft_rl() {

return left_rl;

}

public TextView getCenter_tx() {

return center_tx;

}

public TextView getRight_tx() {

return right_tx;

}

public ImageView getRight_img() {

return right_img;

}

public RelativeLayout getRight_rl() {

return right_rl;

}

public RelativeLayout getTitle_rl() {

return title_rl;

}

public View getView_status_bar_place() {

return view_status_bar_place;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值