Android 工具栏出现在屏幕底部而不是顶部

问题描述 投票:0回答:3

我试图在事件发生后在屏幕底部设置一个工具栏,但该工具栏被绑定到屏幕顶部。知道如何将其设置在屏幕底部吗?

    app:theme="@style/Base.Theme.AppCompat.CompactMenu" >

    <RelativeLayout
        android:id="@+id/toolbarmenucontainer"
        android:layout_alignParentBottom="true"

        android:layout_width="match_parent"
        android:weightSum="3"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <Button
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:clickable="true"
            android:scaleType="fitXY"
            android:layout_weight = "1"
            android:text="test" />



        <Button
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:clickable="true"
            android:scaleType="fitXY"
            android:layout_weight = "1"
            android:text="test2" />

    </RelativeLayout>

</android.support.v7.widget.Toolbar>
android layout toolbar
3个回答
0
投票

在你的activity.xml中

    <include
        android:id="@+id/toolbar"
        android:alignParentBotton="true"
        layout="@layout/toolbar_normal" />

toolbar_normal.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="102dp"
    android:background="@color/yourcolor"
    android:paddingTop="20dp"
    android:paddingBottom="20dp"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">



            <TextView
                android:id="@+id/tittle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"



                android:text="tittle"
                android:textColor="@color/white" />


      <--customise your toolbar here -- >

    </RelativeLayout>
</android.support.v7.widget.Toolbar>

并在 Manifest.xml 将主题应用到您的活动

android:theme="@style/AppTheme.NoActionBar" 

现在如果你想在java中设置标题

 mToolbar = (Toolbar) findViewById(R.id.toolbar);

    tittle= (TextView) findViewById(R.id.tittle);

希望这对你有帮助


0
投票

只需将

toolbar.xml
放入
RelativeLayout
内,如下所示:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="com.erginus.toolbar.MainActivity">

    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </RelativeLayout>
</RelativeLayout>

0
投票

Android 工具栏是新的操作栏。它不绑定到任何活动,这意味着它可以放置在布局中的任何位置,具有高度可定制性,并且可以用作“操作栏”。

详细信息请使用代码这里

XML布局代码

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="com.ahotbrew.toolbar.MainActivity">

    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <TextView
            android:text="@string/hello_brew"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </RelativeLayout>
</RelativeLayout>
© www.soinside.com 2019 - 2024. All rights reserved.