Ich bin gerade mit der Android-Entwicklung aus IOS und wieder auf ein Problem stubled. Und nach 1 Tag des Versuchs entschied ich, dass ich die Leute des Stapelüberlaufs fragen werde.Android ActionBar benutzerdefinierte Layout-Styling
Also mein Problem:
Ich habe eine App und in der Aktionsleiste (standardmäßig keine sherlock) Ich möchte ein Logo und 2 Textzeilen. Und durch das Internet fount ich die setCustomView für die Aktionsleiste. Und das benutzerdefinierte XML wird geladen, aber ich kann das Layout nicht richtig bekommen.
Also zuerst i-Setup die Aktionsleiste:
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
LayoutParams lp1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
View customNav = LayoutInflater.from(this).inflate(R.layout.actionbar, null); // layout which contains your button.
actionBar.setCustomView(customNav, lp1);
}
als der xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:orientation="horizontal"
android:background="@color/Blue">
<TextView
android:id="@+id/text_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_menu"
android:textColor="@color/White"
android:paddingLeft="5dp"
android:layout_gravity="left"/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/Icon"
android:layout_gravity="center"/>
<TextView
android:id="@+id/text_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_help"
android:layout_gravity="right"
android:textColor="@color/White"
android:paddingRight="5dp"/>
</LinearLayout>
Aber das Ergebnis ist etwas, was ich nicht bin auf der Suche nach:
Also was vergesse ich/mache ich falsch/oder sollte ich tun?
Ich liebe dich, ihre getan i taillierte 1 Tag. Und jetzt kann ich weitermachen. Danke – Msmit1993
du bist willkommen ^^ –
Danke das war nützlich. Wenn Sie ein anderes Layout benötigen, verwenden Sie immer ein RelativeLayout als root! – Gibberish