gpt4 book ai didi

android - 自定义工具栏设置不正确

转载 作者:太空狗 更新时间:2023-10-29 14:53:15 25 4
gpt4 key购买 nike

在我的第二个 Activity 中,默认工具栏被设置在某处,但我无法弄清楚。

second_activity.xml:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<include
android:id="@+id/tool_bar"
layout="@layout/toolbar"
></include>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/user_posts"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</ListView>

</LinearLayout>
<ListView android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_below="@id/user_profile"
android:choiceMode="singleChoice"
android:divider="@android:color/black"
android:dividerHeight="1dp"
android:layout_marginLeft="12dp"/>
</android.support.v4.widget.DrawerLayout>

此布局的预览:

enter image description here

深色部分是我的自定义布局。

main_activity.xml

<android.support.design.widget.CoordinatorLayout
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" android:fitsSystemWindows="true"
tools:context=".MainActivity">

<include
android:id="@+id/tool_bar"
layout="@layout/toolbar"
></include>
</android.support.design.widget.CoordinatorLayout>

main_activity.xml 预览:

enter image description here

我的自定义工具栏在主要 Activity 中运行良好。

Android.manifest:

<application
android:name=".NetworkCalls"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DashboardActivity"
android:screenOrientation="portrait"/>
</application>

我已将主题定义为在应用程序级别没有操作栏。

最奇怪的是,当我在实际手机上运行它时,我的第二个 Activity 中没有出现工具栏,而且我的自定义工具栏占据了屏幕上的所有空间。

工具栏.xml:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@drawable/bg_nav_bar"
android:elevation="4dp">

</android.support.v7.widget.Toolbar>

如果有任何帮助,我将不胜感激。

编辑:删除多余的部分

public class DashboardActivity extends AppCompatActivity implements Serializable {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard_activity);

setupDrawerList();
setupDashboardListAdapter();
}
}

最佳答案

抽屉布局应设置为类似于:

<DrawerLayout>
<LinearLayout>
<ToolBar/>
<ListView/>
</LinearLayout>
<ListView/>
</DrawerLayout>

不确定这是否能解决您的问题,请发布您的 Activity onCreateView()

关于android - 自定义工具栏设置不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33624431/

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