按钮的禁用pressed背景颜色 [英] Disable pressed background color of button

查看:545
本文介绍了按钮的禁用pressed背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的按钮只包含字母。每次我preSS它,它有一个黑色的背景。
如何禁用黑色背景?我不希望改变颜色,我想禁用pressed状态。

My button consists of only letters. Every time i press it, it has a black background. How do i disable the black background? I don´t want to change the color, i want to disable the pressed state.

推荐答案

您需要创建绘文件夹下选择和按钮的不同心满意足设置颜色或图像在那里。

You need to create selector under drawable folder and set color or image over there for different sates of the button.

我已经为您创建一个样本应用程序,并粘贴我code片断:

I have created one sample application for you and am pasting code snippet:

code为button_selector.xml包含选择code的按钮,你将需要绘制文件夹下放:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/no_box_selector" android:state_pressed="true"></item>
    <item android:drawable="@drawable/no_box"></item>

</selector>

您将需要把绘,华电国际no_box_selector和PNG图像no_box或任何可绘制文件夹

code为activity_main.xml中,这将是你的主要的XML只包含一个按钮,截至目前:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relRingtone"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/button_selector"
        android:padding="5dp"
        android:text="Click Me"
        android:textColor="#FFF"
        android:textSize="20sp"
        android:textStyle="bold" />

</RelativeLayout>

尝试实现这些东西,让我知道如果你需要任何进一步的assisstance .....

Try implementing these things and let me know if you need any further assisstance.....

所有最优秀的!

这篇关于按钮的禁用pressed背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆