[英]how to put button beside activity titile in android?
嗨我想把按钮放在android的活动标题旁边。 我可以使用setTitle()更改文本,但我没有找到任何允许将按钮放在Activity标题旁边的内容。 我使用的是android 4.0.3。 有谁能够帮我?
在项目名称topbar.xml中创建xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:orientation="vertical"
android:background="@android:color/white">
<TextView
android:id="@+id/title_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MyTitle: NameOfUser"
android:layout_centerVertical="true"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginLeft="20dp"/>
<Button
android:id="@+id/back_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Btn"
android:textColor="@android:color/white"
android:layout_marginLeft="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
只需编写以下内容即可在任何布局中添加此布局:
<include layout="@layout/topbar"/>
希望这会帮助你。
您可以使用custom title bar
,也可以no title theme
为活动使用no title theme
,并将线性布局设置为活动布局上方的子布局,因此您的活动似乎有标题栏 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.