2017-06-12 2 views
2

Der App-Name wird nicht in der App-Leiste angezeigt. Es ist weiß. Ich weiß nicht warum. bitte hilfe. Es zeigte vorher. ich machte viele Veränderungen dann ist jetzt nicht in der Lage esWarum wird der App-Name in der Toolbar in Android nicht angezeigt?

In Haupttätigkeit

.... 
<android.support.v7.widget.Toolbar 
    android:id="@+id/my_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
    android:visibility="visible" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 


    .... 

</RelativeLayout> 

In Stile

<!-- 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> 

In android manifestieren

zu beheben

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> 

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

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

public class MainActivity extends AppCompatActivity { 

    public static final String LOG_TAG = MainActivity.class.getName(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); 
     setSupportActionBar(myToolbar); 

     // Set the content of the activity to use the activity_main.xml layout file 
     setContentView(R.layout.activity_main); 

     // Find the view pager that will allow the user to swipe between fragments 
     ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); 

     // Create an adapter that knows which fragment should be shown on each page 
     ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 

     // Set the adapter onto the view pager 
     viewPager.setAdapter(adapter); 

     TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 

     // Connect the tab layout with the view pager. This will 
     // 1. Update the tab layout when the view pager is swiped 
     // 2. Update the view pager when a tab is selected 
     // 3. Set the tab layout's tab names with the view pager's adapter's titles 
     //  by calling onPageTitle() 
     tabLayout.setupWithViewPager(viewPager); 

    } 
} 
+0

Haben Sie App-Name in res> Werte> Strings –

+2

angegeben, müssen Sie die 'myToolbar' -Initialisierung und' setSupportActionBar() 'Aufruf auf nach' setContentView() 'verschieben. –

Antwort

2

Entweder fügen Sie diese in Ihre Java-Datei. Es setzt die Eigenschaft true für die Titelleiste der Anzeige, die es sichtbar macht.

getSupportActionBar().setDisplayShowTitleEnabled(true); 

Oder diese unter Symbolleiste Element in Ihrem xml hinzufügen

app:title="@string/app_name" 

app wird verwendet, um Eigenschaften zu bezeichnen, in Support-Bibliothek Widgets enthalten.

Am wichtigsten Sie sollten app_name Zeichenfolge in Ihrer string.xml Datei haben.

Für Titel in Zentrum

Sie haben Ihr eigenes benutzerdefiniertes Layout für Aktionsleiste entwerfen und es zu, dass ein. How to set title in centre in ActionBar?

+0

Danke. Weißt du, wie man den Text in der Mitte ausrichtet? – ams92

+0

Antwort bearbeitet. Schau mal. –

0

Sie können wie folgt tun ..

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); 
setSupportActionBar(myToolbar); 
myToolbar.setTitle("Your App Name"); 
0

In Stile

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

Hier ist Ihr Problem. Sie setzen NoActionBar, das heißt, es wird nicht die Leiste oben haben.

Sie sollten DarkActionBar setzen, um die Standard ActionBar zu haben, die Sie vor den Änderungen hatten.

Hoffe es hilft!

+0

App Abstürze - nach https://developer.android.com/training/appbar/setting-up.html müssen wir es hinzufügen.Durch die Verwendung eines dieser Designs wird verhindert, dass die App die native ActionBar-Klasse zum Bereitstellen der App-Leiste verwendet. – ams92

Verwandte Themen