Hallo Zusammen  ![]()
bei meinem kleinen Versuch habe ich eine BottomNavigationBar um zwischen den Activities wechseln zu können. Das klappt auch alles super. Nur leider wird immer das Musik Icon hervorgehoben, egal in welcher Activity ich gerade bin. Wie schaffe ich es, dass immer die aktive Aktivity hervorgehoben wird?
Im Anhang habe ich euch zwei Bilder hochgeladen um das ganze ein wenig zu veranschaulichen ![]()
Einstellungen
Code
		
					
			public class Einstellungen extends AppCompatActivity {
    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_musik:
                    Intent intent0_ = new Intent(Einstellungen.this, Musik.class);
                    startActivity(intent0_);
                    return true;
                case R.id.navigation_lampe:
                    Intent intent_1 = new Intent (Einstellungen.this, Lampe.class);
                    startActivity(intent_1);
                    return true;
                case R.id.navigation_strom:
                    Intent intent_2 = new Intent (Einstellungen.this, Strom.class);
                    startActivity(intent_2);
                    return true;
                case R.id.navigation_wetter:
                    Intent intent_3 = new Intent (Einstellungen.this, Wetter.class);
                    startActivity(intent_3);
                    return true;
            }
            return false;
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_einstellungen);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }
}
	
			Alles anzeigen
	Musik
Code
		
					
			public class Musik extends AppCompatActivity {
    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_einstellungen:
                    Intent intent0_ = new Intent(Musik.this, Einstellungen.class);
                    startActivity(intent0_);
                    return true;
                case R.id.navigation_lampe:
                    Intent intent_1 = new Intent (Musik.this, Lampe.class);
                    startActivity(intent_1);
                    return true;
                case R.id.navigation_strom:
                    Intent intent_2 = new Intent (Musik.this, Strom.class);
                    startActivity(intent_2);
                    return true;
                case R.id.navigation_wetter:
                    Intent intent_3 = new Intent (Musik.this, Wetter.class);
                    startActivity(intent_3);
                    return true;
            }
            return false;
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_musik);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }
}
	
			Alles anzeigen
	
Manifest
Code
		
					
			<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.user.solarpanel">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Musik"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Lampe"/>
        <activity android:name=".Einstellungen"/>
        <activity android:name=".Strom"/>
        <activity android:name=".Wetter"/>
    </application>
</manifest>
	
			Alles anzeigen
	
Layout:
Code
		
					
			<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"
    tools:context="com.example.user.solarpanel.Einstellungen">
    <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_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="64dp"
        android:layout_marginTop="142dp"
        android:text="Einstellungen"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
	
			Alles anzeigen
	Alle Klassen und Layouts sind gleich.
Vielen Dank für eure HIlfe und noch einen schönen Sonntag 