您好,我想在 android 中将按钮放在 Activity 标题旁边。我可以使用 setTitle() 更改文本,但我没有找到任何允许将按钮放在 Activity 标题旁边的内容。我正在使用安卓 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"/>
希望对您有所帮助。
关于java - 如何在android中将按钮放在 Activity 标题旁边?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11373646/