【问题标题】:Get Logo to left in ActionBar在 ActionBar 左侧获取 Logo
【发布时间】:2015-05-08 10:05:01
【问题描述】:

首先我必须说,我知道这不再符合 Google 指南。但我仍然需要知道它。

我正在尝试在我的 ActionBar 中添加 Android 图标。 Logo are not displayed in Actionbar, using AppCompat

这给了我答案。但是我现在的问题是徽标位于 ActionBar 的中间。我想要它在左边。

代码:

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

<style name="MyActionBarLogo" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@color/background_material_dark</item>
    <item name="logo">@drawable/icon</item>
    <item name="displayOptions">useLogo|showHome</item>
</style>

打印屏幕:

任何人的想法? 我觉得这很愚蠢......

编辑:添加清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ap.brecht.myapplication" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

【问题讨论】:

  • 有什么办法可以让图片变小一点? ;-)
  • android:logo 在清单中检查并删除
  • @apk:清单中没有任何徽标。

标签: android android-layout android-actionbar-compat


【解决方案1】:

你为什么不使用工具栏

我认为在你的情况下你应该使用工具栏。

这里是示例代码...

 <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:theme="@style/Toolbar"
    android:background="@color/primary"
    app:theme="@style/Toolbar">


    <TextView
        android:id="@+id/toolbarTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textSize="22dp"
        android:textColor="@android:color/white"/>

    </android.support.v7.widget.Toolbar>

那是我的工具栏,工具栏中间有 textview。 你可以放任何你想要的东西,而不是我用的 TextView 希望这对你有帮助。

【讨论】:

  • 感谢您提供有关工具栏的提示。现在我意识到这是正确的方式。但我现在无法更改我的洞应用程序。但我以后会用这个。我是Android的新手。我来自 C# Win32。
【解决方案2】:

是的,我发现了问题。 真是愚蠢!

图标的大小太大了! 改成 48 * 48 后就可以了!

【讨论】:

  • 这也解决了我的问题。工具栏上的layout_gravity left/right只能设置固定宽度的ImageView
【解决方案3】:

您还可以使用矢量格式 *.svg 的徽标。它会起作用的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 2013-07-24
    相关资源
    最近更新 更多