【发布时间】:2012-11-14 10:31:24
【问题描述】:
我有一个最初为 Android 2.3 设计的应用。现在我正在添加一个带有 ActionBarSherlock 的 ActionBar,一切都很好,除了在运行 4.2 的 Nexus 7 上,它现在将 Holo 主题用于按钮和 EditTexts。之前我的主题是从 Theme.Light 继承的,现在它是从 Theme.Sherlock 继承的。我希望它即使在较新的设备上也能使用旧主题。我怀疑这是由 values-v14 文件夹中的以下行引起的:
<style name="Sherlock.__Theme" parent="android:Theme.Holo">
所以我尝试删除该文件夹和 v11 文件夹只是为了看看它是否能解决问题,但后来 ActionBar 完全消失了。
然后我尝试像这样覆盖 EditText 的样式:
<style name="AppTheme" parent="Theme.Sherlock">
<item name="@android:attr/editTextStyle">@android:style/Widget.EditText</item>
</style>
这应该使小部件不使用 Widget.Holo 主题并使用常规主题,但它不起作用。
如何让 Android 4.0+ 设备在使用 ABS 时使用原始主题而不是 Holo 主题?
下面我发布了一些使用 ABS 的示例应用程序的代码,该应用程序当前显示的是 Holo 主题的 EditText,但应该显示常规的 EditText:
MainActivity.java:
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
public class MainActivity extends SherlockActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
<EditText
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</RelativeLayout>
styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="Theme.Sherlock">
<item name="@android:attr/editTextStyle">@android:style/Widget.EditText</item>
</style>
</resources>
另外,manifest 中的主题是 AppTheme,ABS 被添加为库项目。
【问题讨论】:
标签: android actionbarsherlock android-4.0-ice-cream-sandwich android-theme