更改操作栏上的pressed颜色 [英] Change Action Bar onPressed color

查看:148
本文介绍了更改操作栏上的pressed颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何改变的pssed $ P $色的Andr​​oid操作栏项目。我不是在谈论操作栏的背景颜色,但对湛蓝的状态。我怎样才能改变这种颜色,或至少摆脱它?例如,该应用程序图标与homeAsUpIndicator

我试图改变操作栏风格,也该菜单项的风格,但毫无效果。

感谢

修改的 这是我的执行至今:

我的风格的xml:

 <样式名称=Theme.AppTheme父=@安卓风格/ Theme.Holo>
    <项目名称=机器人:actionBarStyle> @风格/ MyActionBar< /项目>
    <项目名称=机器人:selectableItemBackground> @android:彩色/透明< /项目>
    <项目名称=机器人:windowEnterAnimation> @动画/淡入< /项目>
    <项目名称=机器人:windowExitAnimation> @动画/淡出< /项目>
    <项目名称=机器人:actionBarItemBackground> @android:彩色/透明< /项目>
< /风格>

<样式名称=MyActionBar父=@安卓风格/ Widget.Holo.Light.ActionBar>
    <项目名称=机器人:背景> @可绘制/ actionbarheader< /项目>
    <项目名称=机器人:backgroundStacked> @可绘制/ actionbarheader< /项目>
    <项目名称=机器人:backgroundSplit> @可绘制/ actionbarheader< /项目>
    <项目名称=机器人:titleTextStyle> @风格/ ActionBarTitle< /项目>
    <项目名称=机器人:actionBarItemBackground> @android:彩色/透明< /项目>
    <项目名称=机器人:actionButtonStyle> @风格/ MyActionButtonStyle< /项目>
    <项目名称=机器人:homeAsUpIndicator> @可绘制/ actionbarlogo< /项目>
    <项目名称=机器人:图标> @可绘制/ app_icon< /项目>>
< /风格>

<样式名称=ActionBarTitle父=@安卓风格/ TextAppearance.Holo.Widget.ActionBar.Title>
    <项目名称=机器人:TEXTSIZE> 20SP< /项目>
< /风格>

<样式名称=MyActionButtonStyle父=@安卓风格/ Widget.Holo.Light.ActionButton>
    <项目名称=机器人:背景> @android:彩色/透明< /项目>
< /风格>
 

然后,我有一个绘制的actionbarogo:

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
  <项目机器人:可绘制=@可绘制/ actionbarlogo_on机器人:STATE_ pressed =真/>
  <项目机器人:可绘制=@可绘制/ actionbarlogo_on机器人:state_focused =真/>
  <项目机器人:可绘制=@可绘制/ actionbarlogo_off/>
< /选择器>
 

我的菜单XML的动作栏项目:

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目机器人:ID =@ + ID / ContactsMode
        机器人:图标=@可绘制/ actionbarcontacts
        机器人:标题=@字符串/触点
        机器人:orderInCategory =100
        机器人:showAsAction =总是
        机器人:背景=@机器人:彩色/透明/>
< /菜单>
 

最后,该项目的绘制:

 < XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
  <项目机器人:可绘制=@可绘制/ actionbarcontacts_on机器人:STATE_ pressed =真/>
  <项目机器人:可绘制=@可绘制/ actionbarcontacts_on机器人:state_focused =真/>
  <项目机器人:可绘制=@可绘制/ actionbarcontacts_off/>
< /选择器>
 

下面是我如何创建菜单项的动作条:

 公共布尔onCreateOptionsMenu(功能菜单){
        MenuInflater充气= getMenuInflater();
        inflater.inflate(R.menu.main_menu,菜单);
        actionBar.setIcon(R.drawable.actionbarlogo);
        返回true;
    }

    公共布尔prepareOptionsMenu(功能菜单)在{
         菜单项项= menu.findItem(R.id.C​​ontactsMode);
         如果(ContactsButton)
             item.setVisible(真正的);
         其他
            item.setVisible(假);

         返回true;
    }
 

解决方案

固定它。有一个父活动改变主题,在onCreate方法...

我不知道,你可以以编程的活动中设立了主题:

  setTheme(R.style.MyTheme);
 

I cannot figure out how to change the action bar items "onPressed" color on Android. I'm not talking about the action bar background color but about the blue over state. How can I change the color of this or at least get rid of it? For instance the App Icon with the homeAsUpIndicator.

I tried to change the action bar style and also the menu item style but nothing worked.

Thanks

EDIT Here is my implementation so far:

My style xml:

<style name="Theme.AppTheme" parent="@android:style/Theme.Holo">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:selectableItemBackground">@android:color/transparent</item>
    <item name="android:windowEnterAnimation">@anim/fadein</item>
    <item name="android:windowExitAnimation">@anim/fadeout</item>        
    <item name="android:actionBarItemBackground">@android:color/transparent</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">@drawable/actionbarheader</item>
    <item name="android:backgroundStacked">@drawable/actionbarheader</item>
    <item name="android:backgroundSplit">@drawable/actionbarheader</item>
    <item name="android:titleTextStyle">@style/ActionBarTitle</item>
    <item name="android:actionBarItemBackground">@android:color/transparent</item>
    <item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
    <item name="android:homeAsUpIndicator">@drawable/actionbarlogo</item>
    <item name="android:icon">@drawable/app_icon</item>>
</style>

<style name="ActionBarTitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textSize">20sp</item>
</style>

<style name="MyActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
    <item name="android:background">@android:color/transparent</item>
</style>

Then I have a drawable for the actionbarogo:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/actionbarlogo_on" android:state_pressed="true"/>
  <item android:drawable="@drawable/actionbarlogo_on" android:state_focused="true"/>
  <item android:drawable="@drawable/actionbarlogo_off"/>
</selector>

My menu xml for the action bar items:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/ContactsMode"
        android:icon="@drawable/actionbarcontacts"
        android:title="@string/contacts"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:background="@android:color/transparent" />
</menu>

and finally, the item's drawable:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/actionbarcontacts_on" android:state_pressed="true"/>
  <item android:drawable="@drawable/actionbarcontacts_on" android:state_focused="true"/>
  <item android:drawable="@drawable/actionbarcontacts_off"/>
</selector>

Here is how I create the Menu Items for the ActionBar:

public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_menu, menu);
        actionBar.setIcon(R.drawable.actionbarlogo);
        return true;
    }

    public boolean onPrepareOptionsMenu(Menu menu) {        
         MenuItem item= menu.findItem(R.id.ContactsMode);
         if(ContactsButton)
             item.setVisible(true);      
         else
            item.setVisible(false);

         return true;   
    }

解决方案

Fixed it. There was a parent activity changing the theme in the onCreate method...

I didn't know that you could set the theme programmatically within the activity with:

setTheme(R.style.MyTheme);

这篇关于更改操作栏上的pressed颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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