【发布时间】:2015-01-22 00:44:15
【问题描述】:
注意:这是我的第一个 Android 应用程序,我不知道自己在做什么。在不解释我应该寻找什么的情况下将我引导至文档将无济于事,因为我已经尝试阅读文档并且没有理解它。
我正在 ActionBar 中创建导航下拉菜单,文本是黑色而不是白色(就像我的 ActionBar 中的其余文本一样)。我认为这是因为我在 ArrayAdapter 中使用了错误的东西,但其他值都没有更好的效果。下面是我用来创建下拉菜单的代码。
//NOTE: folders will be created at runtime from data fetched from a web service,
//these values are just test data to get the feature working
folders = new ArrayList<String>(Arrays.asList("All Folders", "comics"));
final ArrayAdapter<String> aa = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
folders
);
final ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
bar.setListNavigationCallbacks(aa, new ActionBar.OnNavigationListener() {
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
final Context c = getApplicationContext();
Toast.makeText(c, folders.get(itemPosition), Toast.LENGTH_SHORT).show();
return true;
}
});
我所看到的示例:
我想了解为什么文本颜色不对,并希望如何用正确的颜色创建它。我不想自定义颜色(就像我发现的很多问题一样),我只想以与 ActionBar 中其他内容相同的样式创建它。
这个styles.xml文件:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
【问题讨论】:
-
simple_list_item_1的源代码在设置文本颜色方面没有任何作用,因此它会尝试遵循应用程序的主题是有道理的。我之前错误地做的是创建视图并在每个视图中更改主题,后来意识到如果我将应用程序主题更改为我希望在整个应用程序中保持一致的内容,那么一切都会按预期运行,而无需以编程方式更改任何内容。有没有可能是您的主题化导致了这个问题? -
能否请您发布您正在使用的主题?您可以在
styles.xml文件中找到它。
标签: android android-actionbar android-spinner