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="QGRyYXdhYmxlL3RpdGxlX2xvZ28=" />
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?


- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01