【问题标题】:Android Toolbar to appear at the bottom of the screen instead of the topAndroid 工具栏出现在屏幕底部而不是顶部
【发布时间】:2016-10-14 18:25:25
【问题描述】:

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

    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>

【问题讨论】:

  • Toolbar 就像任何其他 ViewGroup。将它包裹在一个 RelativeLayout 中并与父底部对齐。
  • 能贴出完整的xml布局代码吗??

标签: android layout toolbar


【解决方案1】:

在你的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);

希望对你有帮助

【讨论】:

    【解决方案2】:

    只需将您包含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>
    

    【讨论】:

      【解决方案3】:

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

      详情用代码here

      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>
      

      【讨论】:

      • 嗨,我按照步骤操作,但它仍然在屏幕顶部而不是底部。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 2013-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多