我试图在按下菜单项时将背景颜色更改为该菜单项。按下时更改背景颜色但不更改颜色。
愿望:
获得:
我能做什么?谢谢
样式.xml
<style name="AppTheme2" parent="android:Theme.Holo">
<item name="android:popupMenuStyle">@style/MyApp.PopupMenu</item>
</style>
<style name="MyApp.PopupMenu" parent="android:Widget.Holo.ListPopupWindow">
<item name="android:popupBackground">@drawable/menu_item_selector</item>
</style>
menu_item_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/menu_item_fondo_pressed" android:state_focused="true"/>
<item android:drawable="@drawable/menu_item_fondo_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/menu_item_fondo"/>
</selector>
最佳答案
迟到的答案,但找到了问题的解决方案。
在 styles.xml 中你有你的 AppTheme:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:dropDownListViewStyle">@style/ListViewStyle</item>
<item name="dropDownListViewStyle">@style/ListViewStyle</item>
<item name="popupMenuStyle">@style/PopupMenu</item>
<item name="textAppearanceLargePopupMenu">@style/PopupMenuTextAppearanceLarge</item>
<item name="textAppearanceSmallPopupMenu">@style/PopupMenuTextAppearanceSmall</item>
<item name="android:textAppearanceLargePopupMenu">@style/PopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">@style/PopupMenuTextAppearanceSmall</item>
</style>
popupMenuStyle 用于 popupMenu 本身,在这种情况下,我们可以在 popupBackground 项中更改那里的未选择背景,就像这样(但您已经知道):
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@drawable/selector_popup_menu_bg</item>
<item name="android:textColor">@color/text_color_white</item>
<item name="android:dropDownSelector">@drawable/selector_popup_menu_dropdown</item>
</style>
还有 textColor 和 dropDownSelector 项目,它们在我测试过的设备上没有做任何事情,但我也在这里更改它们以防万一,因为父 ( Widget.PopupMenu) 也使用它们。
正确更改这些项目的方法是在 AppTheme 中更改它们,就像我在上面的 AppTheme 代码中显示的那样。我不会显示 textAppearances 的代码,因为它不是主题。
我将这些项目中的每一项都添加了两次(有和没有“android:”前缀)的原因是为了让它在 5.0 和 Lollipop 之前的设备上都能工作。唯一的异常(exception)是 popupMenuStyle,如果您使用 Popup 的框架版本,则只需要没有“android:”前缀的项目,但如果您使用 support .v7 版本,那么你需要 android:popupMenuStyle ( see this StackOverflow answer for more info )。
因此,要选择不同的项目背景,我们只需在 dropDownListViewStyle 中更改它(我另外添加了 divider):
<style name="ListViewStyle" parent="@android:style/Widget.ListView">
<item name="android:listSelector">@drawable/selector_popup_menu_dropdown</item>
<item name="android:divider">@color/text_color_white</item>
<item name="android:dividerHeight">1dp</item>
</style>
有趣的部分是listSelector,它是选中项的背景。如果我们只在其中添加@color,则所选项目将不会正确失效(即使您将选择移出它也会保持选中状态),要使其正确而不是颜色,需要使用选择器:
selector_popup_menu_dropdown.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:state_window_focused="false" android:drawable="@android:color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@color/gray_btn_bg_color" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@color/gray_btn_bg_color" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/gray_btn_bg_color" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@color/gray_btn_bg_color" />
<item android:state_focused="true" android:drawable="@color/gray_btn_bg_color" />
对于这种琐碎的事情,解释有点太长了,但我们坚持到了最后。耶!
关于Android:按下菜单项时的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26585045/
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一张背景图片,我想在其中添加一个文本框。我想弄清楚如何将标题放置在其顶部的正确位置。(我使用标题是因为我需要自动换行功能)。现在,我只能让文本显示在左上角,但我需要能够手动定位它的开始位置。require'RMagick'require'Pry'includeMagicktext="Loremipsumdolorsitamet"img=ImageList.new('template001.jpg')img 最佳答案 这是使用convert的ImageMagick命令行的答案。如果你想在Rmagick中使用这个方法,你必须自己移植
如何使用Ruby的默认Curses库获取颜色?所以像这样:puts"\e[0m\e[30;47mtest\e[0m"效果很好。在浅灰色背景上呈现漂亮的黑色。但是这个:#!/usr/bin/envrubyrequire'curses'Curses.noecho#donotshowtypedkeysCurses.init_screenCurses.stdscr.keypad(true)#enablearrowkeys(forpageup/down)Curses.stdscr.nodelay=1Curses.clearCurses.setpos(0,0)Curses.addstr"Hello
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
已经有一个问题回答了如何将“America/Los_Angeles”转换为“PacificTime(US&Canada)”。但是我想将“美国/太平洋”和其他过时的时区转换为RailsTimeZone。我无法在图书馆中找到任何可以帮助我完成此任务的东西。 最佳答案 来自RailsActiveSupport::TimeZonedocs:TheversionofTZInfobundledwithActiveSupportonlyincludesthedefinitionsnecessarytosupportthezonesdefinedb
我想要像“嘿那里”这样的东西变成,例如,#316583。我希望将任意长度的字符串“归结”为十六进制颜色。我不知道从哪里开始。我在想,每个字符串的MD5散列都是不同的-但如何将该散列转换为十六进制颜色数字? 最佳答案 你可以只取几位前几位:require'digest/md5'color=Digest::MD5.hexdigest('Mytext')[0..5] 关于ruby-如何使用Ruby基于字母数字字符串生成颜色?,我们在StackOverflow上找到一个类似的问题:
以下测试中的第3个失败:specify{(0.6*2).shouldeql(1.2)}specify{(0.3*3).shouldeql(0.3*3)}specify{(0.3*3).shouldeql(0.9)}#thisonefails这是为什么呢?这是浮点问题还是ruby或rspec问题? 最佳答案 从rspec-2.1开始specify{(0.6*2).shouldbe_within(0.01).of(1.2)}在那之前:specify{(0.6*2).shouldbe_close(1.2,0.01)}
我在View中有这段代码prawn_document(:page_size=>"A4",:top_margin=>80,:bottom_margin=>40,:background=>"public/uploads/1.png")do|pdf|creation_date=Time.now.strftime('%d-%m-%Y')posts=@posts.eachdo|post|pdf.pad(10)dopdf.textpost.titlepdf.textpost.textendendpdf.page_count.timesdo|i|pdf.go_to_page(i+1)pdf.draw