2017-02-27 3 views
1

マシュマロデバイスよりも低いデバイスでアプリを実行すると、タイトルバーは1つしか表示されません。しかし、私がマシュマロのデバイスでそれを試してみると、ナビゲーションドロワーは2番目のタイトルバーに表示されます。マシュマロデバイスでナビゲーションドロワーを使用しているときに、アクティビティにタイトルバーが2つあるのはなぜですか?

sadasasdsad

誰かがこの問題を解決する方法を教えてくださいことはできますか?

私のMainActivity、activity_main、マニフェスト、スタイルは以下の通りです。

ありがとうございます。

MainActivity

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

たManifest.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> 

style.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> 

答えて

1

私はついにそれを修正しました。私が何をしたか

た:

1.Deletedレイアウト

からツールバーは、このように私のMainActivityを2.Changed。 refer here

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); 
mDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { 
     @Override 
     public void onDrawerClosed(View drawerView) { 
      super.onDrawerClosed(drawerView); 
     } 

     @Override 
     public void onDrawerOpened(View drawerView) { 
      super.onDrawerOpened(drawerView); 
     } 
    }; 
    drawer.post(new Runnable() { 
     @Override 
     public void run() { 
      mDrawerToggle.syncState(); 
     } 
    }); 
    drawer.setDrawerListener(mDrawerToggle); 
    mDrawerToggle.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); 

} 



} 

そしてApptheme自体としての活動のテーマを保ちました。助けのためのそれはrafsanahmad007..Thank @ .. marshmellowとロリポップデバイスの両方に

を働いた

uが。

0

は、ツールバーの初期化後にこのsetSupportActionBar(myToolbar);を追加します。

1

あなたがこれを不足している:値のsetSupportActionBar()

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

/のstyles.xml:

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

テーマを適用:ウル活動のマニフェスト

にマニフェストで:

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

'java.lang.IllegalStateException:このアクティビティには、すでにウィンドウの装飾によって指定されたアクションバーがあります。あなたのテーマでWindow.FEATURE_SUPPORT_ACTION_BARを要求せず、windowActionBarをfalseに設定して、代わりにツールバーを使用してください。 – Ben

+0

このエラーになります。 – Ben

+0

この2行を削除する必要がありました。 getSupportActionBar()。setDisplayHomeAsUpEnabled(true); setSupportActionBar(ツールバー); marshmellowの下のdevies上で実行すると、タイトルバーが表示されなくなりました。 – Ben

関連する問題