1.进入声音设置,勾选“选择操作音”;
2.勾选文件或文件夹时观察是否有选择操作音;
此时应该会对应的有选择操作音的,但为什么无选择操作音?
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false">
</CheckBox>

原来SoundManager对于CheckBox的check事件不感冒,只对click事件产生作用,而对于CheckBox有setOnCheckedChangeListener的API,但是没有setOnClickListener,那CheckBox如何响应onClick事件呢?有一个属性可以在XML中可以配置。
CheckBox的API描述是这样的:
1.When the user selects a checkbox, the CheckBox object receives an on-click event.

To define the click event handler for a checkbox, add the android:onClick attribute to the <CheckBox> element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event. The Activity hosting the layout must then implement the corresponding method.

2.The method you declare in the android:onClick attribute must have a signature exactly as shown above. Specifically, the method must:

•Be public
•Return void
•Define a View as its only parameter (this will be the View that was clicked)

故此时需要修改配置文件:
<CheckBox
android:id="@+id/CheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:onClick="sound">
</CheckBox>

然后在加载该控件对应的配置文件的Activity中实现该函数,这里直接为空函数即可,注意这个函数必须是public权限,返回值为void,指定唯一参数View。
public void sound(View view){

}
OK,大功告成!此时勾选就可以听到清脆的勾选声了。

但是在实际的项目中,由于编译选择的方式可能为user模式,此时user模式对编译进行了优化,该sound函数只是一个空函数,在编译检查的时候发现其未被调用,就直接被优化掉了,在sound函数加一行Log编译不同的user和eng版本,查看是否有Log输出,就可以知道了,那优化掉了,这里点击checkbox此时就会报错,因为找不到该函数。
解决方法,在编译.mk文件中添加下列语句将优化禁用掉,再编译任何模式的版本就不会有问题了。
LOCAL_PROGUARD_ENABLED :=disabled

更多相关文章

  1. android 处理txt文件类FileUtils,利用java反射机制访问非sdk类和
  2. 为开发者准备的最佳 Android(安卓)函数库(2016年版)
  3. android SoundRecorder设计二
  4. 快速编译出WebRTC for Android(安卓)的一次记录
  5. 反编译apk文件,得到其源代码的方法
  6. vnc 项目的几点总结
  7. Qt On Android(安卓)+ protobuf3的使用
  8. Android(安卓)SurfaceFlinger 学习之路(七)----创建图形缓冲区Gr
  9. 在android中通过JNI调用本地方法

随机推荐

  1. Android(安卓)3 开发环境搭建
  2. Android(安卓)的系统属性(SystemProperti
  3. C#/mono开发Android应用程序入门(二)-第一
  4. android系统信息(内存、cpu、sd卡、电量、
  5. Android控件开发——ListView
  6. android中的计步问题及计步传感器分析
  7. Android提权原理
  8. Android开发的未来发展方向,难道android真
  9. Android(安卓)内核分析
  10. Android(安卓)Activity 简介