因为我喜欢这个设计,BottomNavigationView所以我决定用它来实现我的应用程序的新菜单,而不仅仅是使用简单的按钮.
我把这篇文章作为指导.
据BottomNavigationView的文件,其目的是为了
提供应用程序顶级视图之间的快速导航.它主要设计用于移动设备.
在我的情况下,我只希望每个人MenuItem都启动一个活动,但默认情况下总是MenuItem选择一个:
我尝试将颜色设置为白色:
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
Run Code Online (Sandbox Code Playgroud)
仍然,明显选择MenuItem与其他(标题大小更大)不同,这仍然困扰我:
我想出了一个隐藏MenuItem的选择,如:
<item
android:id="@+id/uncheckedItem"
android:title="" />
Run Code Online (Sandbox Code Playgroud)
并提出自己的观点GONE:
bottomNavigationView.getMenu().findItem(R.id.uncheckedItem).setChecked(true);
bottomNavigationView.findViewById(R.id.uncheckedItem).setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
这使得所有MenuItem BottomNavigationView都未被选中,但默认情况下是隐藏标题,因为它有超过3个MenuItems要显示,即使第四个MenuItem要解决GONE:
所以我的问题仍然存在,是否有/取消选择所有MenuItem并保持其标题显示?
我正在创建一个具有以下结构的 android 应用程序:
基于此,似乎 FAB 应该“属于”列表片段,而不是主要活动。
我目前遇到的问题是 FAB 将自己隐藏在底部导航栏后面,如本问题所示。那里有一个很好的解决方案,但这取决于 FAB 与底部导航栏的布局相同。
有没有办法让 FAB 不将自己隐藏在底部导航后面,而无需将 FAB 移动到主要活动(这打破了片段的模块化)?
我的活动布局如下:
<?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=".MainActivity">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_insetEdge="bottom"
app:menu="@menu/navigation" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
其中“片段容器”被选定的片段替换,如下所示:
TodoListFragment fragment = new TodoListFragment();
//if we were started with an intent, pass on any special arguments
fragment.setArguments(getIntent().getExtras()); …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一天让我的Android应用程序在屏幕底部有标签的方法.
在Android开发者网站的样式和主题部分,他们似乎有我想要做的确切示例,但他们没有发现有必要提供一个像样的例子:

我在网上找到的所有提示/解决方案都失败了.我似乎总是得到以下对接丑陋的布局,其中选项卡在应用程序名称旁边的屏幕顶部错位:-(

有没有人知道如何实现这一目标?
非常感谢您的任何提示!
我是android的新手,我使用带有两个菜单的底部导航视图
但我得到了正确的空间
这是我的导航视图,
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorRed"
app:itemIconTint="@color/colorWhite"
app:itemTextColor="@color/colorWhite"
app:menu="@menu/bottom_bar_menu"/>
Run Code Online (Sandbox Code Playgroud)
我正在使用此链接实现BottomNavigationView 我逐步实现了所有内容,但我的导航视图未在屏幕底部显示.
这就是我所做的.
public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
Intent intent = null;
BottomNavigationView navigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
navigationView = (BottomNavigationView) findViewById(R.id.navigation);
navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if(id == R.id.program){
intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
if(id == R.id.access){
try {
manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
overridePendingTransition(R.anim.push_up_in,
R.anim.push_up_out);
} else {
intent …Run Code Online (Sandbox Code Playgroud) 我将要开发一个Android应用程序。在我的应用程序中,我需要在屏幕底部放置操作栏。我从来没有做过。恐怕要以我找到的链接为参考开始它,因为大多数链接建议使用自定义布局,例如RelativeLayout和LinearLayout,因为操作栏不能放在底部。
但是问题是我将使用Recycler View放入无限列表。我担心的是,如果我使用RelativeLayout或LinearLayout,则如果列表太长,操作栏可能不会固定在屏幕底部。因此,我尝试使用自定义小吃栏。
但是我觉得这不是一个好主意,因为小吃店不应该这样使用。但是,如今大多数应用程序都在底部使用操作栏。我想知道的是,在我的情况下,使用底部操作栏的最佳方法是什么。我从未将动作栏放到底部。你有什么建议?