Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改导航栏所选项目的颜色_Java_Android_Android Studio 3.0_App Themes_Android Navigation Bar - Fatal编程技术网

Java 更改导航栏所选项目的颜色

Java 更改导航栏所选项目的颜色,java,android,android-studio-3.0,app-themes,android-navigation-bar,Java,Android,Android Studio 3.0,App Themes,Android Navigation Bar,我曾经 将我的应用程序主题设置为较暗。 现在我遇到了这样一个问题:导航栏中的选定项相对较暗,因此用户几乎看不到它 在我的样式中是否有任何东西可以用于以其他颜色获取选定的导航项? 这是它的一张照片 这是我的活动_main.xml setTheme(R.style.Theme_AppCompat); ..... 您可以为BottomNavigationView指定属性,您可以为正常状态和选定状态设置不同颜色的背景将以下内容添加到BottomNavigationView: <?xml ve

我曾经

将我的应用程序主题设置为较暗。 现在我遇到了这样一个问题:导航栏中的选定项相对较暗,因此用户几乎看不到它

在我的样式中是否有任何东西可以用于以其他颜色获取选定的导航项? 这是它的一张照片

这是我的活动_main.xml

setTheme(R.style.Theme_AppCompat);

.....

您可以为BottomNavigationView指定属性,您可以为正常状态和选定状态设置不同颜色的背景

将以下内容添加到BottomNavigationView:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible"
    tools:context="at.mrminemeet.asciimoji.MainActivity">

.....


    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation"/>

</android.support.constraint.ConstraintLayout>
在drawable文件夹中,创建一个文件bottom_navigation_selector.xml并将其添加到其中:

app:itemIconTint="@drawable/bottom_navigation_selector"       
app:itemTextColor="@drawable/bottom_navigation_selector"

请发布活动的xml代码。您使用的是BottomNavigationView吗?@AnuraagBaishya我现在添加了XML。是否可以在style.XML中添加XML,因为我想让它们随活动的样式而更改,用户可以更改。
<?xml version="1.0" encoding="utf-8"?>
<selector 
   xmlns :android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/colorAccent" android:state_checked="true"/>
    <item android:color="@android:color/darker_gray"  android:state_checked="false"/>
</selector>
bottomNavigationView.setSelectedItemId(R.id.item);