我的android项目中有一个底部导航栏。我有4个标签,只有第一个“注释”被添加标签。对于这些标签,我对每个标签都保留了“意图”。
我有4种布局:
当某人打开应用程序时,他们进入NavigationNotes布局,但是当此人选择笔记本时,bottom_nav_menu.xml
打开,但Notes标签仍然处于选中状态。
每当我选择一个标签时,该标签的文本也应出现,但不会出现。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_notes"
android:enabled="true"
android:icon="@drawable/bottom_notes"
android:title="Notes"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_notebooks"
android:enabled="true"
android:icon="@drawable/bottom_notebook"
android:title="Notebooks"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_premium"
android:enabled="true"
android:icon="@drawable/bottom_premium"
android:title="Premium"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
android:enabled="true"
android:icon="@drawable/bottom_settings"
android:title="Settings"
app:showAsAction="ifRoom" />
</menu>
的代码是:
NavigationNotes.java
我的package com.Notely.Notes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;
import com.Notely.SplashScreenandAccounts.R;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
public class NavigationNotes extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.navigation_notes);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new
BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_notes:
Intent navigationNotes = new Intent(NavigationNotes.this, NavigationNotes.class);
startActivity(navigationNotes);
break;
case R.id.action_notebooks:
Intent navigationNotebooks = new Intent(NavigationNotes.this,
NavigationNotebooks.class);
startActivity(navigationNotebooks);
break;
case R.id.action_premium:
Intent navigationPremium = new Intent(NavigationNotes.this,
NavigationPremium.class);
startActivity(navigationPremium);
break;
case R.id.action_settings:
Intent navigationSettings = new Intent(NavigationNotes.this,
NavigationSettings.class);
startActivity(navigationSettings);
break;
}
return true;
}
});
}
}
的代码是:
auto force = [=](float Q_one, float Q_two, int rad)
{ return ((k * ((Q_one * .000001) * (Q_two * .000001))) / (rad * rad)); };
答案 0 :(得分:0)
我看到您正在使用多个活动。我建议您使用导航组件。您想要做的事情变得容易得多。检查文档:https://developer.android.com/guide/navigation/navigation-ui
答案 1 :(得分:0)
bottomNavigationView.enableAnimation(boolean);
bottomNavigationView.enableItemShiftingMode(boolean);
bottomNavigationView.enableShiftingMode(boolean);
bottomNavigationView.enableItemShiftingMode(boolean);
bottomNavigationView.enableShiftingMode(boolean);
您应该具有类似的功能!