我想在操作栏的中心显示 Logo 。这是我的自定义布局代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ActionBarWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
android:layout_centerInParent="true"
android:padding="8dp"/>
</RelativeLayout>
在 onCreate()
中,我将其用作:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_logo);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#2A2A2A")));
问题是它在正常的 Fragments 和 Activity 中显示良好,但在与 Navigation Drawer 一起使用时会稍微向右移动。以下是图片:
- 错一个:
- 右一:
我做错了什么?谢谢。
最佳答案
然后尝试工具栏。试试这段代码
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:src="@drawable/logo"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
关于android - Logo 在 Action Bar Android 中的中心位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32857438/