现在很多的Android程序都在标题栏上都显示了一些按钮和标题,如下图:
http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:src="@drawable/prv" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="标题栏" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:src="@drawable/next" />
</RelativeLayout>
在创建这个xml时需要注意:
a)使用RelativeLayout的布局
b)特别是右边按钮的属性需要指定layout_centerInParent
2、在Activity中的onCreate中增加下面的代码:
[java]
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebtn);
通过上面的两个步骤就可以实现了上面的效果了。
分享到:
相关推荐
自定义标题居中的ToolBar,也可以将自定义View添加到ToolBar的左边、中间、右边
带有传统标题栏 ActionBar 标题居中 的TitleActivity
自定义View,绘制水平/垂直居中文本。精确度无限接近原生TextView 博客地址http://blog.csdn.net/u014702653/article/details/51985821
实际开发中经常需要变换按钮的图标和文本的位置,因此本菜鸟封装了一个按钮 对外提供一个枚举属性,外界通过赋值相应的枚举值,创建不同类型的按钮暂时提供6种类型 1.默认状态,2.水平左对齐(图标文本位置交换...
uniapp关于支付宝小程序或钉钉小程序标题栏自定义
自定义TextView drawLeft和文本居中显示,以及在代码中动态设置drawable
delphi android 多行文本居中apk
android tv开发和移动端开发最大的不同就是多了一个焦点处理的逻辑。尤其是类似Recyclerview这样本身带有滑动效果,为了醒目的显示当前焦点在什么位置,需要滑动的时候回添加大量的动画、高亮、阴影等效果。 ...
主要介绍了Android Toolbar自定义标题 标题居中的实例代码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
自定义ActionBar使标题居中显示,博客链接:http://blog.csdn.net/tan313/article/details/45039677
Android Toast 自定义背景、图片 随心使用
Android SpannableString实现TextView不同大小文字居中显示。
自定义弹出视图,内容支持传一组菜单标题,也支持自定义view,或者自定义viewController, 支持任意按钮触发,会显示在按钮底部,也支持切换按钮的对齐方式:左对齐、居中、右对齐 (感谢mj老师,部分思路参考)
原始的QMainWindow类只能继承操作系统中的标题栏样式,奇丑无比啊! 这里找了网上其他的自定义样式做了一些修改,添加了菜单栏并对标题位置做了一些修改(居中显示)。
主要介绍了Android编程实现修改标题栏位置使其居中的方法,涉及Android布局设置的简单实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
实现当item的宽度小于RecyclerView的宽度时候,则居中显示
AndroidTV中自定义RecyclerView 让当前焦点item显示在中间,调用smoothToCenter(pos)就可以。
继承系统的TextBox,支持文字垂直居中;自动折行(即WordWrap = True)也支持垂直居中。
Android-Rich-text-Editor.zip,目前支持的样式: 加粗 斜体 下划线 删除线 有序列表 无序列表 左对齐 居中对齐 右对齐 插入图片 文字背景色 插入超链接 @功能 引用 文字颜色(前景色) 插入表情 ...