java - 如何将徽标与操作栏中的左侧大小对齐?
问题描述
我在操作栏中将徽标向左对齐时遇到问题。目前它在中心对齐(默认情况下?)。你知道任何可能有帮助的解决方案吗?
谢谢
我还尝试使用图像视图插入徽标并尝试使用“重力=左”对齐,但这些都不起作用。
这是我的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>
解决方案
你可以尝试使用这个
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
推荐阅读
- android - 如何在 RealmObject 中查询 RealmList(在 Android 中)
- parsing - 使用 PDFBox 的 .NET 版本从 PDF 解析注释/注释:PDFBox.NET-1.8.9
- node.js - MongoDB 聚合和 $lookup 总是返回空数组
- azure - 是否可以从 OMS 监控 Cosmos 指标并设置警报
- java - How to improve the android recorded voice quality
- azure - 从 Azure 存储容器以 Zip 格式下载多个 powershell 文件
- python - 如何检查 orientdb 服务器是否在 sudo 上运行?
- javascript - 如何使用 javaScript 将一些文本放入剪贴板?
- android - Decode JSON file with Kotlin vs Swift
- java - Joda-Time new DateTime() vs DateTime.now()