Ich bin nicht in der Lage, Element in Aktionsleiste auszurichten.Kann jemand bitte helfen Sie mir mit dem Problem.Ich möchte Bild an der linken Ecke und Titel in der Mitte und eine Einstellungsoption in der rechten Ecke ausrichten.Es gibt einen Pfeil um auf andere Aktivität zurückzugehen. Ich möchte diese Option entfernen. Bitte beziehen Sie sich auf den Screenshot für weitere Informationen.Wie positioniere ich das Element in der Aktionsleiste?
ActionBar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/pic13"/>
<TextView
android:id="@+id/actionbar_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxLines="1"
android:clickable="false"
android:focusable="false"
android:longClickable="false"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#FFFFFF" />
</LinearLayout>
Aktivität:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_profile);
final ActionBar abar = getSupportActionBar();
abar.setBackgroundDrawable(getResources().getDrawable(R.color.title));//line under the action bar
View viewActionBar = getLayoutInflater().inflate(R.layout.abs_layout, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(//Center the textview in the ActionBar !
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.MATCH_PARENT,
Gravity.CENTER);
TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.actionbar_textview);
textviewTitle.setText("Test");
abar.setCustomView(viewActionBar, params);
abar.setDisplayShowCustomEnabled(true);
abar.setDisplayShowTitleEnabled(false);
abar.setDisplayHomeAsUpEnabled(true);
abar.setIcon(R.drawable.pic13);
abar.setHomeButtonEnabled(true);
}
statt android: layout_gravity Verwendung android: Schwere –
@helldawg Danke für die Antwort .Aber es ist nicht working.I den Pfeil entfernen möchten, und legen Sie das Bild an diesem Ort. –
Der Pfeil wird angezeigt, weil Sie haben 'abar.setHomeButtonEnabled (true);' –