How to set notification count for Android BottomNavigationView?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am using
<android.support.design.widget.BottomNavigationView/>
to set BottomNavigationView in my android app. My question is
How to set notification count for Android BottomNavigationView? please help me to come out from this..!
android
add a comment |
I am using
<android.support.design.widget.BottomNavigationView/>
to set BottomNavigationView in my android app. My question is
How to set notification count for Android BottomNavigationView? please help me to come out from this..!
android
You shuld add some code and be more specific.
– Gustavo Conde
Jan 27 '17 at 14:14
1
Possible duplicate of Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?
– 476rick
Mar 3 '17 at 10:19
add a comment |
I am using
<android.support.design.widget.BottomNavigationView/>
to set BottomNavigationView in my android app. My question is
How to set notification count for Android BottomNavigationView? please help me to come out from this..!
android
I am using
<android.support.design.widget.BottomNavigationView/>
to set BottomNavigationView in my android app. My question is
How to set notification count for Android BottomNavigationView? please help me to come out from this..!
android
android
edited Feb 27 '18 at 12:03
Paul Hadfield
4,88812754
4,88812754
asked Jan 27 '17 at 14:09
user3068659user3068659
164213
164213
You shuld add some code and be more specific.
– Gustavo Conde
Jan 27 '17 at 14:14
1
Possible duplicate of Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?
– 476rick
Mar 3 '17 at 10:19
add a comment |
You shuld add some code and be more specific.
– Gustavo Conde
Jan 27 '17 at 14:14
1
Possible duplicate of Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?
– 476rick
Mar 3 '17 at 10:19
You shuld add some code and be more specific.
– Gustavo Conde
Jan 27 '17 at 14:14
You shuld add some code and be more specific.
– Gustavo Conde
Jan 27 '17 at 14:14
1
1
Possible duplicate of Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?
– 476rick
Mar 3 '17 at 10:19
Possible duplicate of Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?
– 476rick
Mar 3 '17 at 10:19
add a comment |
3 Answers
3
active
oldest
votes
Create a layout with one Textview like below.
<FrameLayout 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">
<TextView
android:id="@+id/notification_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/circlebackground" // Circle background view
android:padding="3dp"
android:textColor="@color/black"
android:textSize="10sp"
tools:text="9+" />
</FrameLayout>
After initializing the BottomNavgationView, you have to inflate the layout and select the index of View item and set the count.
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(1);
BottomNavigationItemView itemView = (BottomNavigationItemView) v;
View badge = LayoutInflater.from(this)
.inflate(R.layout.homescreen_count, bottomNavigationMenuView, false);
TextView tv = badge.findViewById(R.id.notification_badge);
tv.setText("22+");
itemView.addView(badge);
add a comment |
Just made your custom own bottom bar from horizontal recyclerview, and the class as view and you can have everything at the bottom bar. dont forget Spacing decorator & menu parser if needed.
Can sent you my solution if You want.
add a comment |
First you need to add app:actionLayout
in menu file's item where you want to show badge of your BottomNavigationView like this
<item
android:id="@+id/navigation_chat"
app:actionLayout="@layout/unread_message_layout"
android:icon="@drawable/selector_bottom_navigation_chat"
android:title=""
app:showAsAction="always" />
where unread_message_layout
is the layout which has badge something like below
Here is the XML of that layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUnreadChats"
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_gravity="top|center_horizontal"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/red_circle"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/_7sdp"
android:visibility="visible"
tools:text="5" />
</FrameLayout>
and in your activity where BottomNavigationView
is available, add this to show badges
var mbottomNavigationMenuView = binding.bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
var chatBadge = LayoutInflater.from(this).inflate(R.layout.unread_message_layout,
mbottomNavigationMenuView, false)
var itemView = mbottomNavigationMenuView.getChildAt(2) as BottomNavigationItemView
val tvUnreadChats = chatBadge.findViewById(R.id.tvUnreadChats) as TextView
tvUnreadChats.text = "1"//String that you want to show in badge
itemView.addView(chatBadge)
Here getChildAt(2)
is third item in my BottomNavigationView
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41895883%2fhow-to-set-notification-count-for-android-bottomnavigationview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create a layout with one Textview like below.
<FrameLayout 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">
<TextView
android:id="@+id/notification_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/circlebackground" // Circle background view
android:padding="3dp"
android:textColor="@color/black"
android:textSize="10sp"
tools:text="9+" />
</FrameLayout>
After initializing the BottomNavgationView, you have to inflate the layout and select the index of View item and set the count.
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(1);
BottomNavigationItemView itemView = (BottomNavigationItemView) v;
View badge = LayoutInflater.from(this)
.inflate(R.layout.homescreen_count, bottomNavigationMenuView, false);
TextView tv = badge.findViewById(R.id.notification_badge);
tv.setText("22+");
itemView.addView(badge);
add a comment |
Create a layout with one Textview like below.
<FrameLayout 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">
<TextView
android:id="@+id/notification_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/circlebackground" // Circle background view
android:padding="3dp"
android:textColor="@color/black"
android:textSize="10sp"
tools:text="9+" />
</FrameLayout>
After initializing the BottomNavgationView, you have to inflate the layout and select the index of View item and set the count.
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(1);
BottomNavigationItemView itemView = (BottomNavigationItemView) v;
View badge = LayoutInflater.from(this)
.inflate(R.layout.homescreen_count, bottomNavigationMenuView, false);
TextView tv = badge.findViewById(R.id.notification_badge);
tv.setText("22+");
itemView.addView(badge);
add a comment |
Create a layout with one Textview like below.
<FrameLayout 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">
<TextView
android:id="@+id/notification_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/circlebackground" // Circle background view
android:padding="3dp"
android:textColor="@color/black"
android:textSize="10sp"
tools:text="9+" />
</FrameLayout>
After initializing the BottomNavgationView, you have to inflate the layout and select the index of View item and set the count.
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(1);
BottomNavigationItemView itemView = (BottomNavigationItemView) v;
View badge = LayoutInflater.from(this)
.inflate(R.layout.homescreen_count, bottomNavigationMenuView, false);
TextView tv = badge.findViewById(R.id.notification_badge);
tv.setText("22+");
itemView.addView(badge);
Create a layout with one Textview like below.
<FrameLayout 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">
<TextView
android:id="@+id/notification_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/circlebackground" // Circle background view
android:padding="3dp"
android:textColor="@color/black"
android:textSize="10sp"
tools:text="9+" />
</FrameLayout>
After initializing the BottomNavgationView, you have to inflate the layout and select the index of View item and set the count.
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
BottomNavigationMenuView bottomNavigationMenuView =
(BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
View v = bottomNavigationMenuView.getChildAt(1);
BottomNavigationItemView itemView = (BottomNavigationItemView) v;
View badge = LayoutInflater.from(this)
.inflate(R.layout.homescreen_count, bottomNavigationMenuView, false);
TextView tv = badge.findViewById(R.id.notification_badge);
tv.setText("22+");
itemView.addView(badge);
answered Jan 15 '18 at 20:00
Abish RAbish R
80111024
80111024
add a comment |
add a comment |
Just made your custom own bottom bar from horizontal recyclerview, and the class as view and you can have everything at the bottom bar. dont forget Spacing decorator & menu parser if needed.
Can sent you my solution if You want.
add a comment |
Just made your custom own bottom bar from horizontal recyclerview, and the class as view and you can have everything at the bottom bar. dont forget Spacing decorator & menu parser if needed.
Can sent you my solution if You want.
add a comment |
Just made your custom own bottom bar from horizontal recyclerview, and the class as view and you can have everything at the bottom bar. dont forget Spacing decorator & menu parser if needed.
Can sent you my solution if You want.
Just made your custom own bottom bar from horizontal recyclerview, and the class as view and you can have everything at the bottom bar. dont forget Spacing decorator & menu parser if needed.
Can sent you my solution if You want.
answered Nov 6 '17 at 23:48
Milan JurkulakMilan Jurkulak
314
314
add a comment |
add a comment |
First you need to add app:actionLayout
in menu file's item where you want to show badge of your BottomNavigationView like this
<item
android:id="@+id/navigation_chat"
app:actionLayout="@layout/unread_message_layout"
android:icon="@drawable/selector_bottom_navigation_chat"
android:title=""
app:showAsAction="always" />
where unread_message_layout
is the layout which has badge something like below
Here is the XML of that layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUnreadChats"
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_gravity="top|center_horizontal"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/red_circle"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/_7sdp"
android:visibility="visible"
tools:text="5" />
</FrameLayout>
and in your activity where BottomNavigationView
is available, add this to show badges
var mbottomNavigationMenuView = binding.bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
var chatBadge = LayoutInflater.from(this).inflate(R.layout.unread_message_layout,
mbottomNavigationMenuView, false)
var itemView = mbottomNavigationMenuView.getChildAt(2) as BottomNavigationItemView
val tvUnreadChats = chatBadge.findViewById(R.id.tvUnreadChats) as TextView
tvUnreadChats.text = "1"//String that you want to show in badge
itemView.addView(chatBadge)
Here getChildAt(2)
is third item in my BottomNavigationView
add a comment |
First you need to add app:actionLayout
in menu file's item where you want to show badge of your BottomNavigationView like this
<item
android:id="@+id/navigation_chat"
app:actionLayout="@layout/unread_message_layout"
android:icon="@drawable/selector_bottom_navigation_chat"
android:title=""
app:showAsAction="always" />
where unread_message_layout
is the layout which has badge something like below
Here is the XML of that layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUnreadChats"
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_gravity="top|center_horizontal"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/red_circle"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/_7sdp"
android:visibility="visible"
tools:text="5" />
</FrameLayout>
and in your activity where BottomNavigationView
is available, add this to show badges
var mbottomNavigationMenuView = binding.bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
var chatBadge = LayoutInflater.from(this).inflate(R.layout.unread_message_layout,
mbottomNavigationMenuView, false)
var itemView = mbottomNavigationMenuView.getChildAt(2) as BottomNavigationItemView
val tvUnreadChats = chatBadge.findViewById(R.id.tvUnreadChats) as TextView
tvUnreadChats.text = "1"//String that you want to show in badge
itemView.addView(chatBadge)
Here getChildAt(2)
is third item in my BottomNavigationView
add a comment |
First you need to add app:actionLayout
in menu file's item where you want to show badge of your BottomNavigationView like this
<item
android:id="@+id/navigation_chat"
app:actionLayout="@layout/unread_message_layout"
android:icon="@drawable/selector_bottom_navigation_chat"
android:title=""
app:showAsAction="always" />
where unread_message_layout
is the layout which has badge something like below
Here is the XML of that layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUnreadChats"
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_gravity="top|center_horizontal"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/red_circle"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/_7sdp"
android:visibility="visible"
tools:text="5" />
</FrameLayout>
and in your activity where BottomNavigationView
is available, add this to show badges
var mbottomNavigationMenuView = binding.bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
var chatBadge = LayoutInflater.from(this).inflate(R.layout.unread_message_layout,
mbottomNavigationMenuView, false)
var itemView = mbottomNavigationMenuView.getChildAt(2) as BottomNavigationItemView
val tvUnreadChats = chatBadge.findViewById(R.id.tvUnreadChats) as TextView
tvUnreadChats.text = "1"//String that you want to show in badge
itemView.addView(chatBadge)
Here getChildAt(2)
is third item in my BottomNavigationView
First you need to add app:actionLayout
in menu file's item where you want to show badge of your BottomNavigationView like this
<item
android:id="@+id/navigation_chat"
app:actionLayout="@layout/unread_message_layout"
android:icon="@drawable/selector_bottom_navigation_chat"
android:title=""
app:showAsAction="always" />
where unread_message_layout
is the layout which has badge something like below
Here is the XML of that layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvUnreadChats"
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:layout_gravity="top|center_horizontal"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@drawable/red_circle"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/_7sdp"
android:visibility="visible"
tools:text="5" />
</FrameLayout>
and in your activity where BottomNavigationView
is available, add this to show badges
var mbottomNavigationMenuView = binding.bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
var chatBadge = LayoutInflater.from(this).inflate(R.layout.unread_message_layout,
mbottomNavigationMenuView, false)
var itemView = mbottomNavigationMenuView.getChildAt(2) as BottomNavigationItemView
val tvUnreadChats = chatBadge.findViewById(R.id.tvUnreadChats) as TextView
tvUnreadChats.text = "1"//String that you want to show in badge
itemView.addView(chatBadge)
Here getChildAt(2)
is third item in my BottomNavigationView
answered Jan 3 at 10:07
KishanSolanki124KishanSolanki124
2,2411525
2,2411525
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41895883%2fhow-to-set-notification-count-for-android-bottomnavigationview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You shuld add some code and be more specific.
– Gustavo Conde
Jan 27 '17 at 14:14
1
Possible duplicate of Is there a way to display notification badge on Google's official BottomNavigationView menu items introduced in API 25?
– 476rick
Mar 3 '17 at 10:19