我已经实现了我的应用程序底部的导航视图和我看过的每一个地方上的,如图标上方显示的徽章这个 我不知道这是否是甚至有可能实现.任何帮助表示赞赏.谢谢.
我试图在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
<item
android:id="@+id/nav_gallery"
app:actionViewClass="android.widget.TextView"/>
Run Code Online (Sandbox Code Playgroud)
这是底部导航的菜单。
TextView gallery=(TextView)
MenuItemCompat.getActionView(navigationView.getMenu().
findItem(R.id.nav_gallery)); //getting menu item of bottom nav view
gallery.setText("99+");
Run Code Online (Sandbox Code Playgroud)
但是此代码不适用于底部导航视图。BottomNavigationView 显示时没有设置任何通知计数器。
我想尝试Intellij平台进行android开发,但是即使重新启动它也显示gradle失败。请帮忙。
我试图调整线
implementation 'com.android.support:appcompat-v7:29.+'
Run Code Online (Sandbox Code Playgroud)
到其他版本,但无济于事。
这是我的模块级gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:29.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)
这是我的项目级别Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google() …Run Code Online (Sandbox Code Playgroud)