Ich habe eine einfache Lösung gefunden gewünscht.
Sie haben nur ein Layout für eine benutzerdefinierte ActionBar custom_action_bar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary">
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAllCaps="true"
android:text="name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textStyle="bold" />
<TextView
android:id="@+id/back_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#fff"
android:text="Back"/>
</RelativeLayout>
und dann in Ihrem ExampleActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_date);
ActionBar mActionBar = getSupportActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_action_bar_layout, null);
TextView title = (TextView) mCustomView.findViewById(R.id.title_text);
title.setText("Title");
TextView backButton = (TextView) mCustomView.findViewById(R.id.back_button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
and this is the result.
hey Sie schaffen für das & schließen es ein Layout kann erstellen in Ihrer Aktivität, wenn Sie es brauchen, besuchen Sie und laden Sie meine Beispiel-Demo Sie erhalten https://github.com/mukeshlokare/SampleAndroidApp –