怎么定义Android标题栏工具类
发表于:2025-11-14 作者:千家信息网编辑
千家信息网最后更新 2025年11月14日,这篇文章主要介绍"怎么定义Android标题栏工具类",在日常操作中,相信很多人在怎么定义Android标题栏工具类问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎么定
千家信息网最后更新 2025年11月14日怎么定义Android标题栏工具类
这篇文章主要介绍"怎么定义Android标题栏工具类",在日常操作中,相信很多人在怎么定义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; }}到此,关于"怎么定义Android标题栏工具类"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
标题
文字
右边
工具
按钮
学习
图标
图片
布局
文本
方法
更多
帮助
实用
接下来
上下
上下文
事件
代码
函数
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
湖北推广网络技术有哪些
数据库连接本地配置
数据库中事物英文
数据库e-r
系统的权限信息在哪个数据库
树立网络安全意识手抄报素材
青少年软件开发工具
服务器系统有几种方法
卫星数据是怎么传输到服务器的
医院网络安全突出问题
服务周到的软件开发公司
学软件开发不会英语有事吗
短腿服务器
软件开发中待决策的场景
数据服务器 租
拉萨ipfs集群式服务器
西安软件开发薪资水平
豆瓣的用户数据库
ibm服务器brd
安徽软件开发的公司
医学英文数据库
ai赋能网络安全么
小王任职于某公司软件开发部
梦幻西游手游天龙服务器
博山供应链软件开发价格
日志存储数据库
校园网认证服务器不通
大疆飞行安全精准数据库
实况17数据库数据库
数据库怎样保证数据的有效性