简体   繁体   English

Android AppCompat ActionBar - 左对齐徽标

[英]Android AppCompat ActionBar - Left Align Logo

Within the ActionBar, I am trying to left align the logo and also display the Activity title.在 ActionBar 中,我试图左对齐徽标并显示 Activity 标题。 I'm finding it difficult to left align the logo.... and also display the logo and the title together.我发现很难将徽标左对齐....并将徽标和标题一起显示。

My Activity is extending AppCompatActivity.我的活动正在扩展 AppCompatActivity。 I am using the styles.xml to provide the theme to the app.我正在使用 styles.xml 为应用程序提供主题。 In the styles.xml theme, I have the following:在 styles.xml 主题中,我有以下内容:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
   <item name="actionBarStyle">@style/ActionBarLogoTheme</item>
</style>

Which calls the following:其中调用以下内容:

<style name="ActionBarLogoTheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
   <item name="logo">@drawable/logo</item>
   <item name="displayOptions">useLogo|showHome|showTitle</item>>

   <item name="android:layout_gravity">left</item>
   <item name="android:gravity">left</item>
</style>

In the above, the 'gravity' and 'layout_gravity' don't seem to take affect, and also the 'showTitle' display option doesn't seem to take affect also.在上面,“gravity”和“layout_gravity”似乎没有生效,“showTitle”显示选项似乎也没有生效。 Would anyone be able to help.任何人都可以提供帮助。 The following illustrates what it currently looks like, and what I would like it to look like.下面说明了它目前的样子,以及我希望它是什么样子。

Thank you all.谢谢你们。 在此处输入图像描述

If you want to use an ActionBar you can use:如果要使用ActionBar ,可以使用:

<style name="ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="displayOptions">showHome|useLogo|showTitle</item>
    <item name="logo">@drawable/....</item>
</style>

You can also it programmatically:您也可以通过编程方式:

    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setLogo(R.drawable....);
    getSupportActionBar().setTitle("Title");

在此处输入图像描述

But you can also use a Toolbar :但您也可以使用Toolbar

    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_menu_camera);
    setSupportActionBar(toolbar);

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM