android - 选择器按钮在我的 android 按钮上不起作用。如何解决?

标签 android xml button selector

嗨 Stackoverflow 的 friend 们。我在下面编写了 selector_button.xml 以使我的按钮在点击时更美观。但它根本不影响我的按钮。我哪里错了?

这是selector_button.xml

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

     <!-- When clicked  -->
    <item android:state_pressed="true"
        android:state_selected="true" >
        <shape >
        <gradient        
            android:angle="90"        
            android:centerColor="@color/Lightgray"        
            android:endColor="@color/White"        
            android:startColor="@color/LightBlue"/>    
            <corners android:radius="12dip" />    
            <stroke        
                android:width="0dip"       
                 android:color="@color/LightBlue" />

         </shape>
    </item>
    <!-- When not clicked-->
      <item >
        <shape >
        <gradient        
            android:angle="90"        
            android:centerColor="#ff008888"        
            android:endColor="@color/LightBlue"        
            android:startColor="@color/Lightgray"/>    
            <corners android:radius="12dip" />    
            <stroke        
                android:width="0dip"       
                 android:color="@color/LightBlue" />
      </shape> 
</item>


</selector>

最佳答案

  <!-- When not clicked-->
  <item android:state_pressed="false"> <!-- you need to define ur state to false-->
    <shape >
    <gradient        
        android:angle="90"        
        android:centerColor="#ff008888"        
        android:endColor="@color/LightBlue"        
        android:startColor="@color/Lightgray"/>    
        <corners android:radius="12dip" />    
        <stroke        
            android:width="0dip"       
             android:color="@color/LightBlue" />
     </shape> 
  </item>

关于android - 选择器按钮在我的 android 按钮上不起作用。如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21107784/

相关文章:

java - JAXB 解码期间的默认类字段值

python - 是否可以将文本隐藏在 Tkinter 的按钮/标签内?

python-3.x - Pygame 中按钮内的进度条

url - 如何制作一个仅在特定页面可见的按钮? (创新设置)

java - 如何在安卓日历中添加邮件收件人?

android - 添加 kotlin 协程和空间后无法进行发布构建、proguard 警告

android - 使用 CastPlayer 更改字幕

xml - 在嵌套的 For Each 中对 XSLT 进行排序

java - Spring MVC 3 : Returning XML through @ResponseBody

android - 在android中自动清除应用程序更新时的用户缓存