安卓:AppCompat 21,怎么改回图标和溢图标,自定义的呢? [英] Android: AppCompat 21, how to change the back icon and the overflow icon to a custom one?

查看:416
本文介绍了安卓:AppCompat 21,怎么改回图标和溢图标,自定义的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,直到前几天我用大侦探动作条,但我决定要在整个动作条样式改为新材料设计。在我的旧主题为背部和溢图标,我有一些设置好的对我的主题自定义图标。但在appcompat我想在我的主题定义它,我用它的工具栏上,但它不工作。任何人都知道如何使这一切成为可能?

我的主题我的工具栏上的(生成具有资产工作室):

 <样式名称=Theme.Themewiz父=@风格/ Theme.AppCompat.Light.DarkActionBar>
    <项目名称=机器人:actionBarStyle> @风格/ ActionBar.Solid.Themewiz< /项目>

    <项目名称=机器人:actionBarItemBackground> @可绘制/ selectable_background_themewiz< /项目>
    <项目名称=机器人:popupMenuStyle> @风格/ PopupMenu.Themewiz< /项目>
    <项目名称=机器人:dropDownListViewStyle> @风格/ DropDownListView.Themewiz< /项目>
    <项目名称=机器人:actionBarTabStyle> @风格/ ActionBarTabStyle.Themewiz< /项目>
    <项目名称=机器人:actionDropDownStyle> @风格/ DropDownNav.Themewiz< /项目>
    <项目名称=机器人:actionModeBackground> @可绘制/ cab_background_top_themewiz< /项目>
    <项目名称=机器人:actionModeSplitBackground> @可绘制/ cab_background_bottom_themewiz< /项目>
    <项目名称=机器人:actionModeCloseButtonStyle> @风格/ ActionButton.CloseMode.Themewiz< /项目>

            <! -  Light.DarkActionBar具体 - >
    <项目名称=机器人:actionBarWidgetTheme> @风格/ Theme.Themewiz.Widget< /项目>

    <项目名称=机器人:actionOverflowButtonStyle> @风格/ Theme.AppCompat.Overflow< /项目>

< /风格>

<风格父=@风格/ Widget.AppCompat.ActionButton.OverflowNAME =Theme.AppCompat.Overflow>

    <项目名称=机器人:SRC> @可绘制/ ic_action_overflow< /项目>

< /风格>
 

工具栏的xml:

 < android.support.v7.widget.Toolbar的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / my_awesome_toolbar
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =match_parent
    机器人:=了minHeight?ATTR / actionBarSize
    机器人:背景=?ATTR / colorPrimaryDark
    应用程序:主题=@风格/ Theme.Themewiz
    应用程序:popupTheme =@风格/ ThemeOverlay.AppCompat.Light/>
 

解决方案

使用appcompat 21获得了这幅这些是pretty的方便。

要改回来的图标,你就必须使用支持工具栏作为你的动作条代替。 这篇文章由克里斯·巴内斯应该让你开始。

一旦你完成添加工具栏,所有你需要做的是:

 工具栏=(栏)findViewById(R.id.toolbar_id);
toolbar.setNavigationIcon(R.drawable.back_icon);
 

要更改另一方面溢图标,最简单的方法就是自定义样式添加到主旋律声明。是这样的:

 <资源>
    <! - 基本应用主题。 - >
    <样式名称=Your.Theme父=@风格/ Theme.AppCompat>
        <! - 你的主题项目去这里 - >

        <项目名称=actionOverflowButtonStyle> @风格/溢出< /项目>
    < /风格>

    <! - 风格 - >
    <样式名称=溢出父=@安卓风格/ Widget.AppCompat.ActionButton.Overflow>
        <项目名称=机器人:SRC> @可绘制/ overflow_icon< /项目>
    < /风格>

< /资源>
 

希望有所帮助。

On my project until some days ago I used sherlock actionbar but I dicided to change the whole actionbar style to the new material design. On my old theme for the back and overflow icon I had some custom icons setted on my theme. But on the appcompat I tried define it on my theme where I use it on a toolbar but it's not working. Anyone knows how to make this possible?

My theme where I use on the toolbar(Generated with asset studio):

<style name="Theme.Themewiz" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Themewiz</item>

    <item name="android:actionBarItemBackground">@drawable/selectable_background_themewiz</item>
    <item name="android:popupMenuStyle">@style/PopupMenu.Themewiz</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Themewiz</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Themewiz</item>
    <item name="android:actionDropDownStyle">@style/DropDownNav.Themewiz</item>
    <item name="android:actionModeBackground">@drawable/cab_background_top_themewiz</item>
    <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_themewiz</item>
    <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Themewiz</item>

            <!-- Light.DarkActionBar specific -->
    <item name="android:actionBarWidgetTheme">@style/Theme.Themewiz.Widget</item>

    <item name="android:actionOverflowButtonStyle">@style/Theme.AppCompat.Overflow</item>

</style>

<style parent="@style/Widget.AppCompat.ActionButton.Overflow" name="Theme.AppCompat.Overflow">

    <item name="android:src">@drawable/ic_action_overflow</item>

</style>

Toolbar xml:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_awesome_toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimaryDark"
    app:theme="@style/Theme.Themewiz"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

解决方案

Using appcompat 21 to acheive these is pretty easy.

To change the back icon, you'd have to use the support toolbar as your actionbar instead. This post by Chris Banes should get you started.

Once you're done adding the toolbar, all you have to do is:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_id);
toolbar.setNavigationIcon(R.drawable.back_icon);

To change the overflow icon on the other hand, the easiest way is to add a custom style to the main theme declaration. Something like:

<resources>
    <!-- Base application theme. -->
    <style name="Your.Theme" parent="@style/Theme.AppCompat">
        <!-- Your theme items go here -->

        <item name="actionOverflowButtonStyle">@style/OverFlow</item>
    </style>

    <!-- Styles -->
    <style name="OverFlow" parent="@android:style/Widget.AppCompat.ActionButton.Overflow">
        <item name="android:src">@drawable/overflow_icon</item>
    </style>

</resources>

Hope that helps.

这篇关于安卓:AppCompat 21,怎么改回图标和溢图标,自定义的呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆