gpt4 book ai didi

java - 使用 listView 将工具栏添加到 Activity

转载 作者:行者123 更新时间:2023-11-29 06:48:30 25 4
gpt4 key购买 nike

我正在尝试向我的 Activity 添加一个工具栏,它只有一个元素列表作为内容。这是我的代码,但它不起作用,因为它说我正在使用多根。怎么可能?

<?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"/>

最佳答案

您需要将所有内容放在 RelativeLayout 或 LinearLayout 中。

在这个例子中我使用RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="20sp"
android:layout_below=""@+id/my_toolbar/>


<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"/>

</RelativeLayout>

如果工具栏不是顶部,只需添加工具栏部分 android:layout_alignParentTop="true"

关于java - 使用 listView 将工具栏添加到 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57594968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com