मुझे नहीं पता कि सबसे अच्छा अभ्यास कैसा है, लेकिन आप टूलबार के अंदर कस्टम बैक बटन का उपयोग करके इस वर्कअराउंड को आजमा सकते हैं। लेआउट कोड:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/toolbar_back_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:src="@drawable/ic_back" />
<TextView
android:id="@+id/toolbar_title"
style="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
और गतिविधि में कोड:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView toolbarTitle = (TextView) findViewById(R.id.toolbar_title);
setSupportActionBar(toolbar);
ImageView backButton = (ImageView) findViewById(R.id.toolbar_back_button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
मुझे लगता है कि आप अपनी कार्रवाई बार के लिए एक कस्टम दृश्य बनाने के लिए की आवश्यकता होगी। –
मैंने लेआउट_ग्रैविटी सेट सेंटर पर सेट टूलबार व्यू में टेक्स्ट व्यू जोड़ने का प्रयास किया है। जब टूलबार बैक बटन प्रदर्शित होता है तो यह काम नहीं करता है। –
आप एक कस्टम व्यू (एक बटन (बैक) और एक टेक्स्टव्यू (शीर्षक) युक्त क्षैतिज रैखिक लेआउट बना सकते हैं और उन्हें केंद्र बना सकते हैं। –