How to highlight ImageView when focused or clicked?(聚焦或单击时如何突出显示 ImageView?)
问题描述
一个很好的例子是在 Twitter 启动屏幕(应用程序首次启动时看到的带有大图标的屏幕),或者当您聚焦应用程序图标时,甚至只是查看应用程序托盘.
A good example of this is either on the Twitter launch screen (the screen with the large icons that is seen when the application is first launch) or even just look at the application tray when you focus an application icon.
基本上,我需要突出显示 ImageView,其中突出显示的轮廓与 ImageView 中的图像一致,看起来就像是该图像的边框.我还想自定义突出显示以使其具有某种颜色并使其淡出.
Basically I need to highlight an ImageView where the highlight contours to the image within the ImageView and looks like it's a border to that image. I would also like to customize the highlight to have it be a certain color and for it to fade out.
谢谢,
帅气
推荐答案
你需要为ImageView
的src
属性分配一个状态列表drawable.换句话说,该状态列表对于选中、按下、未选中等会有不同的图像——这就是 Twitter 应用程序的工作方式.
You need to assign the src
attribute of the ImageView
a state list drawable. In other words, that state list would have a different image for selected, pressed, not selected, etc. - that's how the Twitter App does it.
如果你有一个 ImageView:
So if you had an ImageView:
<ImageView style="@style/TitleBarLogo"
android:contentDescription="@string/description_logo"
android:src="@drawable/title_logo" />
src 可绘制对象 (title_logo.xml) 如下所示:
The src drawable (title_logo.xml) would look like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/title_logo_pressed"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/title_logo_pressed"/>
<item android:state_focused="true" android:drawable="@drawable/title_logo_selected"/>
<item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/title_logo_default"/>
</selector>
Google IO Schedule 应用程序就是一个很好的例子.
这篇关于聚焦或单击时如何突出显示 ImageView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:聚焦或单击时如何突出显示 ImageView?
基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01