我在网上发现了一些关于这个问题的问题.不幸的是,到目前为止我所尝试的一切都没有成功.
有标题说,我需要更改我的操作栏的背景颜色.
该项目的最小sdk为9,最大sdk为19.
我在我的res/values文件夹中创建了一个xml文件:
red_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@color/red</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
colors.xml存储在res/values中
<resources>
<color name="red">#FF0000</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
以及我改变主题的清单部分
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >
Run Code Online (Sandbox Code Playgroud)
但没有变化.问题出在哪儿?应用程序接受代码,因为如果我改变了:
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
Run Code Online (Sandbox Code Playgroud)
至
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar ">
Run Code Online (Sandbox Code Playgroud)
它确实改变了我的应用程序的主题,所以问题在于风格,但我不知道如何解决它.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">@color/red</item>
<item name="background">@color/red</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud) 我在Logcat中遇到此错误.有谁知道它是什么?
08-22 19:02:57.830: E/dalvikvm(660): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11
Run Code Online (Sandbox Code Playgroud) 我已经安装了支持库,以便在android pre API 11中使用操作栏
当我启动应用程序时,logcat会出现此错误:
08-20 19:54:41.600: I/dalvikvm(9828): Failed resolving Landroid/support/v7/widget/SearchView$5; interface 809 'Landroid/view/View$OnLayoutChangeListener;'
08-20 19:54:41.600: W/dalvikvm(9828): Link of class 'Landroid/support/v7/widget/SearchView$5;' failed
08-20 19:54:41.600: E/dalvikvm(9828): Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11
08-20 19:54:41.600: W/dalvikvm(9828): VFY: unable to resolve new-instance 734 (Landroid/support/v7/widget/SearchView$5;) in Landroid/support/v7/widget/SearchView;
08-20 19:54:41.600: D/dalvikvm(9828): VFY: replacing opcode 0x22 at 0x0002
08-20 19:54:41.600: D/dalvikvm(9828): VFY: dead code 0x0004-000a in Landroid/support/v7/widget/SearchView;.addOnLayoutChangeListenerToDropDownAnchorSDK11 ()V
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我,我搜索网络,但我什么也没发现.谢谢
MainActivity.Java
package com.example.fanculo;
import android.os.Bundle;
import android.app.SearchManager;
import android.content.Context;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
import …Run Code Online (Sandbox Code Playgroud) error-handling android runtime class android-support-library