zoukankan      html  css  js  c++  java
  • Andorid之使用ImageView和Selector配置文件制作多样式按钮(默认、点击、灰掉)

         在做地图的时候  有个需求:

         当可以缩放地图的时候,放大按钮可以使用。当不可以使用地图的时候,放大按钮不可以使用。放大按钮在默认状态下是一个背景,点击的状态下是另一个背景。

         废话少说,代码奉上:

        一、ImageView配置文件片段。

            

       <ImageView
        	android:id="@+id/ivZoomOut"
        	android:layout_height="wrap_content"
        	android:layout_width="wrap_content"
        	android:layout_marginRight="10px"
        	android:layout_marginBottom="10px"
        	android:src="@drawable/zoom_out_2"
        	/>
    

     二、样式控制配置文件zoom_out_2.xml:

      

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">     
    <!-- Disabled -->
    	<item android:state_enabled="false" 
    	      android:state_pressed="false" 
    	      android:textColor="@color/red"
    		  android:drawable="@drawable/zoom_out_disable" />     
    <!-- Pressed -->
    	<item android:state_enabled="true" 
    	      android:state_pressed="true"
    		  android:textColor="@android:color/white" 
    		  android:drawable="@drawable/zoom_out_pressed" />     
    <!-- Focused -->
    <!-- 	<item android:state_enabled="true" 
    	      android:state_focused="true"
    		  android:textColor="@android:color/white" 
    		  android:drawable="@drawable/list_item_focused" /> -->     
    <!-- Default -->
    	<item android:state_enabled="true" 
    	      android:state_pressed="false" 
    	      android:drawable="@drawable/zoom_out_default"/>
    </selector> 
    

     三、代码控制:

      

     if(**){
               zoomOutView.setEnabled(false);
         }else{
              zoomOutView.setEnabled(true);
         }
    
  • 相关阅读:
    firefox禁止更新提示
    laravel性能优化笔记片段
    laravel 7 在线教育项目实操笔记(2)后台基础功能开发
    一、笔记片段 迁移文件相关(创建表 字段 添加假数据等)
    路由、控制器笔记
    laravel rbac笔记片段
    二 笔记片段
    三 文件上传片段
    分享5个有趣的 JavaScript 代码片段
    异步上传文件
  • 原文地址:https://www.cnblogs.com/likehua/p/2516610.html
Copyright © 2011-2022 走看看