徽标在Android Action Bar中的居中位置 [英] Center position of logo in Action Bar Android
本文介绍了徽标在Android Action Bar中的居中位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要在操作栏的中央显示徽标.这是我的自定义布局代码:
I want to display the logo at the centre of the Action Bar. Here's my custom layout code:
<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")));
问题是它在正常的片段"和活动"中显示正常,但在与导航抽屉"一起使用时会向右移动一点.这是图片:
The issue is it displays fine in normal Fragments and Activity but shifts a little to the right when used with Navigation Drawer. Here are the images:
- 错误之一:
- 第一权利:
我做错了什么?谢谢.
推荐答案
然后尝试使用工具栏.试试这个代码
Then try ToolBar. Try this code
<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 Action Bar中的居中位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文