我想将单选按钮的圆圈颜色(现在为粉色,如下图所示)更改为深蓝色,适用于菜单中的所有项目。
那是我的菜单:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.aoutir.mohamed.movies.MainFragment"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--<item-->
<!--android:id="@+id/action_refresh"-->
<!--android:title="@string/Refresh"-->
<!--android:orderInCategory="200"/>-->
<group android:checkableBehavior="single">
<item
android:id="@+id/action_popular"
android:orderInCategory="100"
android:title="@string/action_popular"
app:showAsAction="never" />
<item
android:id="@+id/action_rated"
android:orderInCategory="200"
android:title="@string/action_rated"
app:showAsAction="never" />
<item
android:id="@+id/action_favourites"
android:orderInCategory="300"
android:title="@string/action_favourites"
app:showAsAction="never" />
</group>
</menu>
style.xml(这是我整个应用程序的样式):
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--<item name="android:popupMenuStyle">@style/PopupMenu</item>-->
</style>
<!--<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">-->
<!--<item name="android:popupBackground">@android:color/white</item>-->
<!--<item name="colorAccent">@color/colorPrimary</item>-->
<!--<item name="android:textColor">@android:color/black</item>-->
<!--</style>-->
<style name="AppTheme.NoActionBar" parent="Base.Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MovieTheme" parent="AppTheme">
<item name="actionBarStyle">@style/ActionBar.Solid.Movies.NoTitle</item>
<item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
</style>
<style name="ActionBar.Solid.Movies.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">@mipmap/pop_corn</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar" >
<item name="overlapAnchor">false</item>
<item name="android:overlapAnchor" tools:ignore="NewApi">false</item>
</style>
<style name="AppTheme.PopupOverlay" parent="Base.ThemeOverlay.AppCompat.Light">
</style>
<style name="CircularProgress" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/sky_blue</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">@mipmap/ic_sort</item>
<item name="android:contentDescription">@string/action_sort</item>
</style>
</resources>
还有与我的菜单相关的Java代码(检查是否选择了项目并执行某些操作):
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.main_fragment_menu,menu);
super.onCreateOptionsMenu(menu,inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_popular:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.action_rated:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
case R.id.action_favourites:
if (item.isChecked()) item.setChecked(false);
else item.setChecked(true);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
提前感谢任何帮助。
app:itemIconTint="@color/black"
来设置单选项的图标颜色。 - vishal-wadhwa