android - Android 2.3.5 上的 ActionBar 和 SearchView 问题

标签 android android-actionbar

我在我的应用程序中实现了一个 ActionBar 以及一个 SearchView 小部件。它在 Nexus 7、HTC Sensation 等设备上工作得很好——我相信任何 Android 版本早于 3.0 的地方。但它不能在 Android 2.3.5 的手机上运行。

当程序在旧设备上运行时,有没有办法“不显示”操作栏和其他不受支持的东西?

这是我在我的旧设备上运行时得到的错误日志,请原谅我的长度,不太明白哪个位有用:

09-27 12:15:03.008: I/dalvikvm(824): Failed resolving Lcom/example/stroke/handling/MainActivity; interface 407 'Landroid/widget/SearchView$OnQueryTextListener;'
09-27 12:15:03.008: W/dalvikvm(824): Link of class 'Lcom/example/stroke/handling/MainActivity;' failed
09-27 12:15:03.008: D/AndroidRuntime(824): Shutting down VM
09-27 12:15:03.008: W/dalvikvm(824): threadid=1: thread exiting with uncaught exception (group=0x400205a0)
09-27 12:15:03.018: E/AndroidRuntime(824): FATAL EXCEPTION: main
09-27 12:15:03.018: E/AndroidRuntime(824): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.stroke.handling/com.example.stroke.handling.MainActivity}: java.lang.ClassNotFoundException: com.example.stroke.handling.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.stroke.handling-1.apk]
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1743)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.ActivityThread.access$1500(ActivityThread.java:132)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.os.Looper.loop(Looper.java:150)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.ActivityThread.main(ActivityThread.java:4277)
09-27 12:15:03.018: E/AndroidRuntime(824):  at java.lang.reflect.Method.invokeNative(Native Method)
09-27 12:15:03.018: E/AndroidRuntime(824):  at java.lang.reflect.Method.invoke(Method.java:507)
09-27 12:15:03.018: E/AndroidRuntime(824):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-27 12:15:03.018: E/AndroidRuntime(824):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-27 12:15:03.018: E/AndroidRuntime(824):  at dalvik.system.NativeStart.main(Native Method)
09-27 12:15:03.018: E/AndroidRuntime(824): Caused by: java.lang.ClassNotFoundException: com.example.stroke.handling.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.stroke.handling-1.apk]
09-27 12:15:03.018: E/AndroidRuntime(824):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
09-27 12:15:03.018: E/AndroidRuntime(824):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
09-27 12:15:03.018: E/AndroidRuntime(824):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
09-27 12:15:03.018: E/AndroidRuntime(824):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1735)
09-27 12:15:03.018: E/AndroidRuntime(824):  ... 11 more

附言我不想使用 ActionBarSherlock!

最佳答案

哎呀,

Remaining backward-compatible

If you want to provide an action bar in your application and remain compatible with versions of Android older than 3.0, you need to create the action bar in your activity's layout (because the ActionBar class is not available on older versions).

To help you, the Action Bar Compatibility sample app provides an API layer and action bar layout that allows your app to use some of the ActionBar APIs and also support older versions of Android by replacing the traditional title bar with a custom action bar layout.

这是我问题的答案吗?

编辑:那个示例应用很糟糕。

关于android - Android 2.3.5 上的 ActionBar 和 SearchView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620225/

相关文章:

安卓java.lang.NumberFormatException : Invalid int: "res/drawable-hdpi/ic_menu_share.png"

android - 操作栏抽屉切换自定义图标

android - SearchView.isFocused 总是返回 false

Android 进度条样式语法

java - 在 Activity 中没有从 EditText 获得任何值(value)

android - android canvas 中位图的同步旋转、平移和缩放

android - 更改操作栏菜单为 appcompat 选择的文本颜色

android - 向 Toast 显示查询

java - 使用向左/向右拖动来倒回可绘制的动画

android - 自定义 ActionBar 项目上的 ClickListener (ActionBarSherlock)