的ImageButton不上点击与透明背景突出不上、突出、透明、背景

2023-09-12 11:15:52 作者:`寂寞的執著リ

我已经设置了一个ImageButton的是透明的,所以图标backgrond面板类似Android的动作条相匹配。这看起来不错,我想它。

然而,当背景是透明的,没有你看,当你preSS操作栏中的透明按钮作为青色亮点。

我可以有一个ImageButton的是透明的,也有点击时高亮闪光灯?

 <的ImageButton
    机器人:ID =@ + ID / nextItemButton
    风格=机器人:ATTR / buttonStyleSmall
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentRight =真
    机器人:layout_alignParentTop =真
    机器人:背景=@空
    机器人:SRC =@可绘制/ ic_media_ff/>
 

解决方案

所有你需要做的是设置适当的背景。如果你希望它是透明的,正常状态和青色的pressed说。

创建一个StateListDrawable像这次在 RES /绘制目录。

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

这种方式的默认背景是透明的。当pressed背景有你指定的颜色(而不是颜色,你可以在这里使用任何可绘制)。

海空设计 如何在平面设计中有效地应用透明背景

I've set up an ImageButton to be transparent, so the icon matches the backgrond panel like the Android ActionBar. This looks fine as I want it to.

However, when the background is transparent, there isn't the blueish highlight you see as when you press a transparent button in the action bar.

Can I have an ImageButton that is transparent and also has the highlight flash when clicked?

<ImageButton
    android:id="@+id/nextItemButton"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="@null"
    android:src="@drawable/ic_media_ff" />

解决方案

All you need to do is to set the proper background. If you want it to be transparent in normal state and blueish in pressed stated.

Create a StateListDrawable like this one in res/drawable directory.

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

This way the default background is transparent. When pressed the background has the color you specified (instead of color you can use any drawable here).