[英]How can i put my logo on Center of Android Action Bar?
This is my menu-main.xml. 这是我的menu-main.xml。
The picture below the code shows where I want to put the logo on my app. 代码下方的图片显示了我想在应用程序上放置徽标的位置。
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.akam.billettogram.MainActivity">**strong text**
<item
android:id="@+id/logo"
app:showAsAction="always"
android:title=""
android:layout_gravity="center"
android:icon="@drawable/logo"/>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
</menu>
So, the easiest way for you to do it is creating a new Empty Activity in Android Studio, make sure it is Empty and not Blank ! 因此,最简单的方法是在Android Studio中创建一个新的Empty Activity,确保它为Empty而不是Blank !
This template will build all the code needed: 该模板将构建所需的所有代码:
AppBarLayout
, Toolbar
and CoordinatorLayout
. AppBarLayout
, Toolbar
和CoordinatorLayout
创建布局。 So... you will just have to add your icon and maybe a TextView
inside the automatically created Toolbar
(in the layout.xml ) as seen in the following snippet : 所以...您只需要在自动创建的
Toolbar
(在layout.xml中 )内添加图标 ,也许还可以添加TextView
,如以下代码片段所示 :
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<LinearLayout
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="@android:drawable/btn_star_big_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Hello world"
android:textColor="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
Below is an image with the result: 下面是带有结果的图像:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.