我怎么能实现在Android电子按钮非矩形矩形、按钮、电子、我怎么能

2023-09-07 23:03:54 作者:我不太會說話

您好,我要实现这个布局。它有这个布局。

hi i have to realize this layout . it has this layout.

我可以尝试使用图标作为imagebuttons而是一个按钮的活动状态有点像一个!

I could try to use the icons as imagebuttons but the active state of a button is somewhat like this one !

我应该如何着手呢?

推荐答案

您应该使用选择如下:

prepare 2图像,按钮状态,并把它变成 RES /绘制文件夹中。

button_normal_green.png - 默认图像按钮

button_normal_green.png – Default image button.

button_ pressed_yellow.png - 当按钮被pressed显示

button_pressed_yellow.png – Display when button is pressed.

现在,创建RES /绘制/文件夹中一个新的XML文件,以任何名义你想要的,在这种情况下,我们只给一个名为new_button.xml。确定该文件的按钮状态是属于哪个形象。

Now, create a new XML file in "res/drawable/" folder, in whatever name you want, in this case, we just give a name as "new_button.xml". This file defined which button state is belong to which image.

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

     <item android:drawable="@drawable/button_normal_green" />
  </selector>

3.设置背景按钮

<ImageButton
    android:id="@+id/imageButtonSelector"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/new_button" />

看一看完整的例子