我在用
compile 'com.android.support:design:25.0.0'
Run Code Online (Sandbox Code Playgroud)
Android底部导航视图及其高度已固定,并显示带有小文本的小图标.我的问题是如何增加他们的尺寸?我试图xml通过样式改变文件中的大小......所有其他属性都在工作,除了textsize属性.
如果是这样,我能否实际做到这一点,那么请写一个代码
我在片段中使用滚动视图,但是当键盘按原样显示时屏幕没有向上滚动。这是场景:我有 mainActivity,它有底部导航栏和一个框架布局,它用作活动的容器。这是代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<android.support.design.widget.BottomNavigationView
android:background="@color/clear_white"
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
app:itemIconTint="@color/blue_navbar_icon"
app:itemTextColor="@color/blue_navbar_icon"
app:menu="@menu/navigation" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
片段屏幕有一些输入字段和按钮,它们包裹在约束布局中,然后约束布局包裹在 scrollView 中,以便在键盘处于活动状态时可以向上滚动。这是片段xml文件的代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include
android:id="@+id/app_bar_new"
layout="@layout/app_bar_new"
app:layout_constraintBottom_toTopOf="@+id/btn_get_location"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn_get_location"
style="@style/btn_style"
android:layout_width="match_parent"
android:layout_height="43dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="11dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp"
android:layout_marginStart="11dp"
android:layout_marginTop="12dp"
android:text="@string/get_location_btn_str"
app:layout_constraintBottom_toTopOf="@+id/tv_long"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/app_bar_new" />
<EditText
android:id="@+id/et_name_of_attr"
style="@style/input_field_style"
android:layout_width="0dp"
android:layout_height="47dp"
android:layout_marginBottom="7dp"
android:layout_marginEnd="11dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="11dp" …Run Code Online (Sandbox Code Playgroud) 因为我喜欢这个设计,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并保持其标题显示?
我一直在将新的(ish)材质 BottomAppBar 与标准的底部导航视图相结合。我的xml是这样的:
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:fabAlignmentMode="center">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@android:color/transparent"
app:itemTextAppearanceActive="@style/AppTheme.Text.BottomNavText.Active"
app:itemTextAppearanceInactive="@style/AppTheme.Text.BottomNavText"
app:labelVisibilityMode="labeled"
app:menu="@menu/bottom_nav_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
Run Code Online (Sandbox Code Playgroud)
在以前的版本 - 1.0.0 - 这工作正常,我仍然可以按预期看到 FAB 插图。唯一的小缺点是这个版本的材质组件库没有对底部应用栏的高度效果进行排序,所以栏和上面的内容之间的区别并不明确。
当我升级到最新的库(在撰写本文时我相信是)时implementation 'com.google.android.material:material:1.1.0-alpha09',我得到了 BottomAppBar 的高度效果,但是当我将透明背景应用到 BottomNavigationView 时,我得到了一个非常奇怪的视觉效果,对于我的生活我不能理解。
如果我删除透明背景颜色,那么效果会消失,但我会丢失 FAB 插图,如下所示:
如果我完全删除底部导航视图子项,并且只有底部应用栏,我会看到正常的视觉效果,但没有我的导航:
我会喜欢: - 一个很好的解决方案,将底部导航视图合并到 BottomAppBar 中,同时保留 1.1.0 版库的良好提升效果,并且在其中有效地包含 BottomNavigationView,因此我保留了该导航组件的所有优点 - 或解释到底是什么导致了这种奇特的第一次海拔效应,理想情况下是一种修复它的方法
android material-design bottomnavigationview material-components bottomappbar
我有底部导航,我也<fragment>用FragmentContainerView它替换了标签,这给了我关于它没有设置 NavController 的错误,然后我发布了这个问题并解决了这个问题,但是当方向改变并选择项目时,我得到了以下错误在底部导航
java.lang.IllegalStateException: 在调用 getGraph() 之前必须先调用 setGraph()
片段容器
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/mobile_navigation" /
Run Code Online (Sandbox Code Playgroud)
寻找片段
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_classes, R.id.navigation_schedule, R.id.navigation_settings
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController)
Run Code Online (Sandbox Code Playgroud) android orientation-changes android-fragments bottomnavigationview
android-layout material-design bottomnavigationview material-components-android material-you
Android有新的ui元素 - BottomNavigationView
我不想在xml文件中包含我的菜单.我将从后端收到有关菜单项和订单的信息.我想动态创建它们并设置BottomNavigationView在onCreate()方法中.我可以这样做吗?
我试图在BottomNavigationView没有使用任何库的情况下为项目添加徽章,但不知何故BottomNavigationView没有显示徽章(custom_view)
main_view.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hrskrs.test.MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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/colorPrimary"
app:itemIconTint="@color/colorAccent"
app:itemTextColor="@color/colorPrimaryDark"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
bottom_navigation_menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item_test"
android:icon="@mipmap/ic_launcher"
android:title="action1"
app:showAsAction="always" />
<item
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:title="action2"
app:showAsAction="ifRoom" />
<item
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:title="action3"
app:showAsAction="ifRoom" />
</menu>
Run Code Online (Sandbox Code Playgroud)
活动扩展自AppCompatActivity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu = bottomNavigationView.getMenu();
menu.clear();
getMenuInflater().inflate(R.menu.bottom_navigation_main, menu);
MenuItem item = menu.findItem(R.id.item_test);
item = MenuItemCompat.setActionView(item, R.layout.custom_view); …Run Code Online (Sandbox Code Playgroud) android android-layout bottomnavigationview material-components material-components-android
我正在使用Android应用程序的底部导航视图.我增加了图标的大小,但现在图标会在文本上运行.这是我看到的:
这是根据谷歌设计文档的底部导航视图的图表:
数字10,我想改变那个填充,但当我查看导航栏的属性时,我看不到我能做到的地方.如何将其更改为较小的数字?在我的bottom_layout.xml中,我正在设置我的项目,如下所示:
<item
android:id="@+id/menu_notifications"
android:title="Professionals"
android:icon="@drawable/ic_action_name"
app:showAsAction="ifRoom"
/>
Run Code Online (Sandbox Code Playgroud)
如何更改底部文本填充?
谢谢
我们正在使用 createBottomTabNavigator。在其中一个选项卡中包含顶部的搜索栏。单击该搜索栏时,我们正在打开键盘。但是键盘也向上推底部标签栏。打开键盘时,我们需要底部标签栏保持在底部。
const SignedIn = createBottomTabNavigator(
{
Followers: {
screen: FollowerStack,
...
},
Search: {
screen: SearchStack,
},
Home: {
screen: HomeStack,
},
Bookmarks: {
screen: BookmarkStack,
},
Profile: {
screen: ProfileStack,
}
},
{
initialRouteName: "Home",
tabBarPosition: 'bottom',
swipeEnabled: false,
animationEnabled: false,
tabBarOptions: {
keyboardHidesTabBar: true,
showIcon: true,
showLabel: false,
activeTintColor: "red",
inactiveTintColor: "gray",
adaptive: true,
safeAreaInset: {
bottom: "always"
}, …Run Code Online (Sandbox Code Playgroud) javascript android react-native react-native-android bottomnavigationview
android ×9
material-components-android ×2
android-view ×1
bottomappbar ×1
javascript ×1
material-you ×1
menuitem ×1
react-native ×1
scrollview ×1
title ×1
xml ×1