设置toolbar标题居中
来源:互联网 发布:php curl 设置头部 编辑:程序博客网 时间:2024/05/19 17:03
废话不多说,直接上代码。然后调用
customizeToolbar(mToolbar);
代入参数即可。亲测有效public void customizeToolbar(Toolbar toolbar){ // Save current title and subtitle final CharSequence originalTitle = toolbar.getTitle(); final CharSequence originalSubtitle = toolbar.getSubtitle(); // Temporarily modify title and subtitle to help detecting each toolbar.setTitle("title"); toolbar.setSubtitle("subtitle"); for(int i = 0; i < toolbar.getChildCount(); i++){ View view = toolbar.getChildAt(i); if(view instanceof TextView){ TextView textView = (TextView) view; if(textView.getText().equals("title")){ // Customize title's TextView Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER_HORIZONTAL; textView.setLayoutParams(params); } else if(textView.getText().equals("subtitle")){ // Customize subtitle's TextView Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER_HORIZONTAL; textView.setLayoutParams(params); } } // Restore title and subtitle toolbar.setTitle(originalTitle); toolbar.setSubtitle(originalSubtitle); }}
0 0
- 设置toolbar标题居中
- Toolbar设置标题居中
- toolbar标题设置居中
- Toolbar标题居中怎么设置
- Android设置Toolbar的标题居中
- Android设置Toolbar的标题居中
- Toolbar 标题居中
- toolbar标题居中
- Android标题居中的Toolbar
- Android自学之路,ToolBar的使用标题居中颜色设置
- ToolBar标题文字居中的方法
- 【Android开发】Toolbar与标题居中
- 如何设置ActionBar标题居中
- Android-Toolbar标题居中与字体大小和颜色
- 关于toolbar标题居中及隐藏右侧overflowButton
- Android Toolbar设置向上箭头,标题等
- Android toolbar的标题设置无效
- Android Toolbar设置向上箭头,标题等
- 控制反转(IoC)与依赖注入(DI)
- LintCode 直方图最大矩形覆盖
- Redhat 7修改默认运行级别方法 --RHEL7使用systemd创建符号链接指向默认运行级别(文字,图形界面)
- linux内核分析学习笔记:操作系统的进程切换
- [Android]Android中Application、静态变量和Sharedpreferences的使用与区别
- 设置toolbar标题居中
- Android应用性能剖析全攻略
- 开发中碰到的问题:Unparsed aapt error(s)! Check the console for output.
- WebView之 单击手势不响应的解决方案
- Android Material Design学习之四CardView
- CSS画出一个三角形
- Swift 2.0 异常处理--throws
- Android基本功:Handler消息传送机制
- ORM框架的学习总结