android - 如何更改 onClick 高亮显示的形状?

标签 android onclick icons highlight

目前,我的应用程序的 GridView 中有图标。单击它们时,它们周围会短暂出现一个橙色方 block 作为突出显示。唯一的问题是,我认为这看起来很业余,并且想更改形状,以便它剪辑 GridView 中的图标而不是大正方形。如果您不确定我的意思,它可以在仪表板/主屏幕上的 Catch Notes 应用程序中成功执行。我只是想知道是否有人知道解决这个问题的方法,或者它只是一个小的布局属性。

https://play.google.com/store/apps/details?id=com.threebanana.notes&hl=en

提前致谢,我们将不胜感激所有帮助!

它看起来就像下图中的这个 EditText。它以橙色与 EditText 边框的方式正是单击时它与主屏幕中的图标边框的方式。

enter image description here

最佳答案

首先,在布局文件中指定可绘制背景:

android:background="@drawable/bg_your_view"

然后编辑可绘制的bg_your_view文件:

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

最后,为按下正常状态创建相应的drawable文件:

  • bg_your_view_pressed.xml 包含您想要突出显示的形状和颜色。
  • bg_your_view_normal.xml类似,只是没有高亮效果。

关于android - 如何更改 onClick 高亮显示的形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11131005/

相关文章:

python - 使用py2exe在.exe中嵌入图标,在Vista中可见?

android - 单击按钮之前执行的 Flutter 代码

cocoa - 将 NSImage 导出/导入为 ICO

java - ActiveAndroid 使用现有数据库

android - 用于后台任务的最佳做法是什么?

delphi - 如何在 Delphi 中将事件附加到 IHTMLDocument2 链接元素?

javascript - 我怎样才能避免按钮点击两次的重复请求

基于列表项的文本值的 css 样式

android - notifyDatasetChanged() id 不工作

android - 如何修复 Unity android 版本上的 "activityStartTrigger: not whiteListed"?