gpt4 book ai didi

android - 为什么在 Marshmallow 设备中使用抽屉导航时我的 Activity 中有 2 个标题栏

转载 作者:行者123 更新时间:2023-11-29 19:21:03 24 4
gpt4 key购买 nike

当我在低于棉花糖设备的设备上运行我的应用程序时,它只显示一个标题栏。但是当我在棉花糖设备上尝试时,抽屉导航出现在第二个标题栏中。像这样。

sadasasdsad

谁能告诉我如何解决这个问题?

我的MainActivity、activity_main、 list 和样式如下。

谢谢。

主要 Activity

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


try {


Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTitle("Case Sheets");

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

myDB = MainActivity.this.openOrCreateDatabase("hoteldb", MODE_PRIVATE, null);

mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
mRecyclerView.setLayoutManager(mLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.addItemDecoration(new DividerItemDecoration(getApplicationContext()));
try {

showList();

}catch (Exception e)
{
Toast.makeText(getApplicationContext(),"Please Synch the data",Toast.LENGTH_SHORT).show();
}



} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Please Login",Toast.LENGTH_LONG).show();
Intent logout = new Intent(MainActivity.this, LoginPage.class);
startActivity(logout);

}



}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />



</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView android:id="@+id/nav_view"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_gravity="start" android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.digitalmenu" >

<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


<application
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" > -->
<activity
android:name=".Oodo.Login.LoginPage"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".Oodo.CaseSheets.MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"></activity>

</application>

样式.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />




<style name="heading_text">
<item name="android:textColor">#ff000000</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
<item name="android:padding">5dp</item>
</style>
<style name="HomeButton">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:background">@null</item>
</style>

</resources>

最佳答案

你错过了这个:setSupportActionBar()

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setSupportActionBar(toolbar);

在 values/styles.xml 中:

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

应用主题:您在 list 中的 Activity

在 list 中:

  <activity
android:name=".Oodo.CaseSheets.MainActivity"
android:theme="@style/AppTheme.NoActionBar" //change here

关于android - 为什么在 Marshmallow 设备中使用抽屉导航时我的 Activity 中有 2 个标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42479602/

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