Android:如何使微调框禁用外观已禁用 [英] Android : How to make a spinner disabled look disabled

查看:71
本文介绍了Android:如何使微调框禁用外观已禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的>如何制作微调框已禁用"状态看起来已禁用?.

我尝试了帖子中提到的解决方案,即

I tried the solution mentioned in the post, ie

((Spinner) spinner).getSelectedView().setEnabled(false);
spinner.setEnabled(false);

但是getSelectedView()返回null.我还尝试过手动选择一个项目,然后调用getSelectedView,但它仍返回null.

However getSelectedView() returns null. I also tried manually selecting an item and than calling getSelectedView but it still returns null.

推荐答案

像这样在res/drawable文件夹中创建一个可绘制的选择器

Create a drawable selector in the res/drawable folder like this

custonspinner.xml

custonspinner.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- disabled state -->
  <item android:state_enabled="false" android:color="#9D9FA2" /> 
  <item android:color="#000"/>
</selector>

//您也可以在选择器中使用可绘制对象代替颜色

// You can give the drawable also instead of colors in the selector

在微调器中像这样设置背景资源

In your spinner set the background resource like this

android:backgroundResource="@drawable/customspinner"

这篇关于Android:如何使微调框禁用外观已禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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