android - 工具栏出现在 android 应用程序的底部而不是顶部
问题描述
我正在为我的 android 应用程序使用工具栏并禁用操作栏。对于主要活动,工具栏正确出现在顶部,但对于应用程序设置(这是一个片段),它出现在底部,对此有任何帮助
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:name="com.example.app.Settings$NewsPreferenceFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"
tools:context="com.example.app.Settings">
<include xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
解决方案
请检查您是否使用具有重力=“底部”或相对布局的线性布局
确保代码驻留在这样的地方
理想情况下,布局应该看起来像
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
orientation="vertical">
<include xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:name="com.example.app.Settings$NewsPreferenceFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.app.Settings">
</LinearLayout>
推荐阅读
- user-agent - Core Web Vitals 的用户代理是什么?
- swift - Swift - 如何在不同函数中更新变量,当所有函数在页面加载时运行,然后才能声明变量
- python - KivyMD 带有下拉菜单的文本字段
- c++ - 是否有一个 C++ API Linux 系统调用可以告诉您可执行文件链接了哪些共享库?
- typescript - 模板文字作为 Typescript 中的函数参数
- c# - 首选项 Xamarin.Essentials - 第一次检查是否为空?
- asp.net-core - IConfigureOptions 的生命周期
和 IHostingEnvironment 实现服务类 - sql - Angular fullcalendar 显示来自 Angular 服务的事件
- c# - C# 中的自定义字符串占位符
- jolt - JOLT Spec 合并来自多个级别的嵌套数组并读取子项下的父键值