Android工具栏将显示在屏幕底部而不是顶部
我试图在事件发生后在屏幕底部设置工具栏,但工具栏被绑定到屏幕顶部。你知道怎么把它设置在屏幕底部吗Android工具栏将显示在屏幕底部而不是顶部,android,layout,toolbar,Android,Layout,Toolbar,我试图在事件发生后在屏幕底部设置工具栏,但工具栏被绑定到屏幕顶部。你知道怎么把它设置在屏幕底部吗 app:theme=“@style/Base.theme.AppCompat.CompactMenu”> Android工具栏是新的操作栏。它不绑定到任何活动,这意味着它可以放置在布局中的任何位置,具有高度的自定义能力,可以用作“操作栏” 代码的详细信息 XML布局代码 <RelativeLayout xmlns:android="http://schemas.android.co
app:theme=“@style/Base.theme.AppCompat.CompactMenu”>
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>
在您的activity.xml中
<include
android:id="@+id/toolbar"
android:alignParentBotton="true"
layout="@layout/toolbar_normal" />
现在,如果您想在java中设置标题,请使用
mToolbar = (Toolbar) findViewById(R.id.toolbar);
tittle= (TextView) findViewById(R.id.tittle);
希望这将帮助您简单地将
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>
工具栏与任何其他视图组一样。将其包装在RelativeLayout中,并将其与父屏幕底部对齐。您能发布完整的xml布局代码吗?您好,我按照步骤操作,但它仍然位于屏幕顶部而不是底部。
android:theme="@style/AppTheme.NoActionBar"
mToolbar = (Toolbar) findViewById(R.id.toolbar);
tittle= (TextView) findViewById(R.id.tittle);
<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>