首页 > 解决方案 > 如何将徽标与操作栏中的左侧大小对齐?

问题描述

我在操作栏中将徽标向左对齐时遇到问题。目前它在中心对齐(默认情况下?)。你知道任何可能有帮助的解决方案吗?

谢谢

我还尝试使用图像视图插入徽标并尝试使用“重力=左”对齐,但这些都不起作用。

这是我的toolbar_main.xml

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:logo="@drawable/cookme_logo">

这是我的 activity_home.xml

<include
    layout="@layout/toolbar_main"
    android:id="@+id/toolbar"/>

这是 ActivityHome.java

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    ((Toolbar) findViewById(R.id.toolbar)).setLogo(R.drawable.cookme_logo);

这是 AndroidManifest.xml

 <application

    android:allowBackup="true"
    android:icon="@drawable/cookme_logo"
    android:label="@string/app_name"
    android:roundIcon="@drawable/cookme_logo"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity android:name=".ActivityHome">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

标签: javaandroid

解决方案


你可以尝试使用这个

ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_USE_LOGO);
actionBar.setIcon(R.drawable.ic_launcher);`


your question is probably answered here :


https://stackoverflow.com/questions/42713859/add-icon-to-the-left-of-the-title-in-the-action-bar-in-android



推荐阅读