这是我的代码:
<PreferenceCategory
android:summary="Fade information"
android:title="Fade Effects">
<CheckBoxPreference
android:title="Fade In/Out"
android:defaultValue="false"
android:key="fadeIn"/>
<CheckBoxPreference
android:title="Heartbeat"
android:defaultValue="false"
android:key="heartbeat" />
<CheckBoxPreference
android:title="Pulse"
android:defaultValue="false"
android:key="pulse" />
<CheckBoxPreference
android:title="None"
android:defaultValue="true"
android:key="none" />
</PreferenceCategory>
我基本上试图弄清楚如何使这些CheckBox显示为原样,但让用户无法点击它们。
答案 0 :(得分:6)
使用08-05 10:44:03.538 29161-29161/com.example.lewan.appka E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3606)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17367)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3601)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17367)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x3
at android.content.res.Resources.getText(Resources.java:230)
at android.widget.TextView.setText(TextView.java:3769)
at com.example.lewan.appka.MainActivity.NewGame(MainActivity.java:65)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3601)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17367)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
是不正确的,因为这实际上完全禁用了android:enabled="false"
(它还会将其灰化,这是主要问题)。你想要做的是:
View
这只会阻止用户点击android:clickable="false"
,但不会正式“禁用”它。我认为这更符合您的需求。
答案 1 :(得分:1)
使用XML中的android:enabled="false"
或Java代码中的setEnabled()
。
答案 2 :(得分:0)
如果您不想使CheckboxPreference变灰,可以在xml中使用android:selectable="false"
。