java - 使用 listView 将工具栏添加到活动
问题描述
我正在尝试向我的活动添加一个工具栏,它只有一个元素列表作为内容。这是我的代码,但它不起作用,因为它说我正在使用多个根。这怎么可能?
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp" >
</TextView>
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
style="@style/HeaderBar"
app:theme="@style/ActionBarThemeOverlay"
app:popupTheme="@style/ActionBarPopupThemeOverlay"
android:elevation="4dp"/>
解决方案
是的……安卓是对的。
只能有一个根布局。您可以添加相对布局或线性布局作为根布局。根布局将包装您的文本视图和工具栏。
谢谢
推荐阅读
- lambda - 使用lamda表达式java比较两个地图
- jquery - jQuery与移动菜单冲突
- javascript - 使用 appollo/neo4j-graphql-js 查询接口实现不起作用
- php - 如何在准备好的语句php中的不同行中插入多条记录
- http - 为什么我们有 3 个使用这个 HTTP 的 set-cookies?
- python - 将带有 url 的数组传递到模板中
- excel - Apache POI比较excel中的2列数据
- c# - Linq Dynamics 将 N 添加到我的参数中
- job-scheduling - PBSPro 不正确的 QList 条目导致 Q 状态
- android - 微调器未在设备上显示,但在模拟器上