gesetzt wurde Zuerst weiß ich, dass es viele SO gibt, die ähnliche Probleme ansprechen. Ich habe sie alle durchforstet, und keine der bereitgestellten Antworten hilft mir, mein Problem zu lösen.Android ActionBar zeigt keinen Titel an, der in Code
Ich kann nicht den Titel (oder die Schaltfläche zurück) auf meiner android.support.v7.widget.Toolbar
Komponente angezeigt werden. Egal was ich versucht habe.
Ich habe eine Android-Aktivität, die das wie (my_activity.xml) aussieht:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable name="infos" type="com.mycompany.orm.adapters.ListViewAdapter"/>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/buttonBackground"
android:elevation="4dp"
android:logo="@drawable/ic_close_white_24dp" />
<ListView
android:id="@+id/my_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/windowBackground"
bind:items="@{infos.list}"/>
</RelativeLayout>
</layout>
und die Aktivität onCreate
als (MyActivity.java):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
if (toolbar != null) {
toolbar.setTitle("My Name Here"); // Never shows up
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setTitle("Hello World!"); // Never shows up
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24dp);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.show();
}
}
}
Aber mit In diesem Code sehe ich nur eine leere Symbolleiste. Ich sehe nie den Text (entweder My Name Here
oder Hello World!
. Wenn ich jedoch die Zeile bind:title="Testing"
zum Toolbar
Element der XML hinzufügen, sehe ich den Titel erscheint als Testing. Allerdings möchte ich in der Lage sein, das Aussehen des zu manipulieren Symbolleiste/ActionBar, so würde ich mag es zu tun, um der Lage sein, im Code.
Sieht jemand, wo das könnte falsch
? gehen
Das sollte das gleiche wie oben sein nein? 'ActionBar actionBar = getSupportActionBar(); if (actionBar! = null) {actionBar.setTitle ("Hallo Welt!"); } ' – Brett
Verwenden Sie das folgende Thema? –
John
@Brett: Ich habe das gleiche XML und Code und es angezeigt "Hallo Welt!" com.android.support:appcompat-v7 23.0.0, – John