java - 如何在android中将按钮放在 Activity 标题旁边?

标签 java android android-layout

您好,我想在 android 中将按钮放在 Activity 标题旁边。我可以使用 setTitle() 更改文本,但我没有找到任何允许将按钮放在 Activity 标题旁边的内容。我正在使用安卓 4.0.3。谁能帮帮我?

enter image description here

最佳答案

在你的项目名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/

相关文章:

java - 用java编译一个Jar

android - AdMob "Not enough space to show ad"错误

parsing - 如何以编程方式将 Java 代码(方法)解析为控制流图

java - hibernate 检索查询不起作用

java - 如何在 spring boot 中使用 findAll 方法与 crudrepository

java - 我如何知道 Long.MAX_VALUE 达到 'long' 值

java - Android 应用程序在转而使用 java 创建布局后停止工作

android - 如何在 Google Play 分阶段发布期间更新/升级您的 Android APK

android - 软键盘上推布局或隐藏操作栏

java - 显示图像 动态查看