2017-04-27 3 views
1

style.xmlUnable Aktionsleiste auf Haupttätigkeit

hier i absichtlich deaktivieren Aktionsleiste angezeigt werden, weil ich es auf meinem Splash-Screen

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
      <!-- Customize your theme here. --> 
      <item name="colorPrimary">@color/colorPrimary</item> 
      <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
      <item name="colorAccent">@color/colorAccent</item> 
     </style> 

MainActivity.java

erscheinen möchte nicht nach Ich möchte, dass Aktionsleiste in der Hauptaktivität vorhanden ist, indem Sie set supportactionbar verwenden, aber die Aktionsleiste funktioniert nicht, nachdem ich den Code ausgeführt habe, und der gesamte Prozess ist ohne Fehler. Kann mir jemand sagen, was mit meinem Code nicht stimmt.

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

Antwort

0

Sie haben zwei Möglichkeiten.

1: Fügen Sie in Ihrem XML manuell eine Symbolleiste hinzu. Beispiel:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:minHeight="?attr/actionBarSize" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:titleTextColor="@android:color/white" 
     android:background="?attr/colorPrimary"> 
    </android.support.v7.widget.Toolbar> 

</LinearLayout> 

Siehe https://guides.codepath.com/android/Using-the-App-Toolbar für weitere Informationen Symbolleiste.

OR

2: Erstellen Sie ein neues Thema für Ihre Splash-Screen und legen Sie es in Ihrem Manifest. Beispiel:

<activity 
     android:name=".view.activity.SplashActivity" 
     android:theme="@style/Splash"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
     </intent-filter> 
    </activity> 

Und dann in styles.xml Ihrer App:

<style name="Splash" parent="Theme.AppCompat.NoActionBar"> 
    <item name="android:windowFullscreen">true</item> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="android:windowBackground">@drawable/splash_screen</item> 
</style> 

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

Entweder man davon ist in Ordnung, aber persönlich habe ich immer nur über einen separaten Stil für meinen Splash-Screen, die Dinge sauber zu halten und einfach.