首页 > 解决方案 > 在linearLayout(android kotlin)的工具栏顶部放置一个按钮

问题描述

我想在linearLayout中的工具栏顶部放置一个按钮,就像在照片中一样在此处输入图像描述。有没有办法做到这一点?

这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/constr"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SettingsAct.SettingsActiv">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarSettings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorAccent" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>

标签: androidandroid-linearlayout

解决方案


这边走:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/constr"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".SettingsAct.SettingsActiv">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarSettings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorAccent" >

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
    </android.support.v7.widget.Toolbar>



</LinearLayout>

推荐阅读