2016-04-03 11 views
0

Ich versuche, meiner App Toolbar hinzuzufügen, aber irgendwie funktioniert es nicht. Weder Titel noch Aktionssymbole werden angezeigt. Auch das Menü ":" wird nicht angezeigt. Hier sind meine Codes:Symbolleistensymbole werden nicht in AppCompat-Aktivität angezeigt

Style.xml:

<resources> 

    <!-- Base application theme. --> 
    <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> 


    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

</resources> 

Menu_main.xml:

<menu 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" 
    tools:context="com.example.vaibhav.thirdeye.MainActivity"> 
    <item 
     android:id="@+id/action_settings" 
     android:orderInCategory="100" 
     android:title="@string/action_settings" 
     app:showAsAction="never" /> 

    <item android:id="@+id/next" 
     android:title="@string/next" 
     android:orderInCategory="200" 
     android:icon="@drawable/next_arrow" 
     app:showAsAction="always"/> 
</menu> 

content_main.xml:

<?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" 
    android:background="@drawable/back_splash" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="com.example.vaibhav.thirdeye.MainActivity" 
    tools:showIn="@layout/activity_main" 
    app:theme="@style/AppTheme.NoActionBar"> 

    <include 
     android:id="@+id/app_bar" 
     layout="@layout/app_bar" /> 

MainActivity.java:

public class MainActivity extends AppCompatActivity { 

    public static final String EXTRA_MESSAGE = "com.example.vaibhav.thirdeye.MESSAGE"; 
    Toolbar toolbar; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 


     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     //Adding Custom toolbar 
     toolbar = (Toolbar) findViewById(R.id.app_bar); 
     setSupportActionBar(toolbar); 
     toolbar.setNavigationIcon(R.drawable.next_arrow); 
     toolbar.setTitle("ThirdEye"); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.menu_main,menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 

     int id = item.getItemId(); 

     switch (id){ 
      case R.id.action_settings: 
       Toast settings = Toast.makeText(this, "Voila!", Toast.LENGTH_SHORT); 
       settings.show(); 
      case R.id.next: 
       Toast next = Toast.makeText(this, "Voila!", Toast.LENGTH_SHORT); 
       next.show(); 
     } 
     return true; 
    } 
} 

app_bar.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="@dimen/icon_size" 
    android:background="@color/colorPrimary"> 

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

Output Screenshot:

Output Screenshot:

Jeder hilft ????

+0

Können Sie auch einen Screenshot hinzufügen? –

+0

hinzugefügt. @DanielZolnai. PLZ Hilfe. –

+0

Aufruf setSupportActionBar (Symbolleiste); erst nachdem alle Toolbar-Attribute wie title navigationicon usw. gesetzt wurden ... –

Antwort

0

Entfernen Sie zusätzliche Symbolleisten in Ihrem MainActivity activity_main.xml-Layout, es wird Ihre Probleme lösen.