How to Change BottomNavigationBar attributes? - android

how to disable magnify and modify font_size of selected tab in BottomNavigationBar Android, I just wanna change the tab's color, don't magnify the tab, what should i do, thanks!
is there any attribute to change some attribute in this widget?
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="#+id/mainTabBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:animateLayoutChanges="false"
android:background="#color/white"
android:splitMotionEvents="false"
app:bnbActiveColor="#color/colorPrimary"
app:bnbBackgroundColor="#color/white"
app:bnbInactiveColor="#color/gray"
app:bnbMode="mode_fixed"
tools:override="true"/>

That BottomNavigationBar is a custom component and probably has its own method of styling or inheriting a style. Can you please share how it works or references to the documentation of the component? Thank you!

Related

Reduce height between text and icon in TabItem under TabLayout

I have seen this post before with the same question, but recently Google introduced another TabLayout
QUESTION:
Is there a way of reducing the space between text and icon using an attribute for instance, or another google-maintainable method in order to avoid having to go through creating a separate layout with text and an icon?
My current layout looks like this:
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager.widget.ViewPager
android:id="#+id/mViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/homeTabs">
<com.google.android.material.tabs.TabLayout
style="#style/Widget.MaterialComponents.TabLayout"
android:id="#+id/homeTabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:tabIndicatorColor="#color/clear_blue">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="#drawable/one_svg"
android:text="#string/one"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="#drawable/two_svg"
android:text="#string/two"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="#drawable/three_svg"
android:text="#string/three"/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="#drawable/four_svg"
android:text="#string/four"/>
</com.google.android.material.tabs.TabLayout>
</RelativeLayout>
As I could understand after some tests, no.
The Google Tab Item is created to match with the material design rules, so the space between icon and text is calculated following that rules, as you can read here in the post you reported.
Only way is to create a custom layout, with an ImageView and a TextView and inflating it in the TabItem.
I suggest you this way, because is fully customizable so you can create pratically what you want.
Hope I helped you! If you have any question write a comment.
No, looks like you cannot do that with just attribute. This change will definitely require creating custom layout. And this gonna be the right way - almost any application has custom views. But this class looks complicated (there is source code). So there is inner class TabView, that contains ImageView and TextView, and there is method inflateAndAddDefaultIconView(). The easiest way for you my opinion is just to copy that class into your project and change it as you need, the license (Apache 2.0) allows you to do that.

Android make overlaping FloatingActionButton on BottomNavigation

I would like to design this layout on my project:
as many googleing AFIAK is some library to can design that on Android but I can't find it, I take this screen shot from Android material website. Can anybody help me to design that? thanks in advance
At the bottom of the material design page there's a link on how you can implement that on Android, Flutter, iOS, etc.
As for Android, you'll have to use the BottomAppBar widget to achieve what you want. You can also read more about it on the docs.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Other components and views -->
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:navigationIcon="#drawable/ic_menu_24"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/bar"/>
</android.support.design.widget.CoordinatorLayout>
Taken from here.
You can change the FAB position by using the method setAnchorId(int) with the following parameters:
FAB_ALIGNMENT_MODE_CENTER
FAB_ALIGNMENT_MODE_END
Alternatively you can set that in the XML using the app:layout_anchor attribute.
P.S.: As stated on the docs, to change the BottomAppBar background use the app:backgroundTint attribute instead of the default android:background.

Add elevation to BottomNavigationView

Here's what my bottom navigation bar in XML looks like:
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/white"
app:itemBackground="#color/primary"
app:elevation="8dp"
app:menu="#menu/main_activity_bottom_nav"/>
If I remove app:itemBackground="#color/primary", the elevation shows properly, but the moment I add that back in, it disappears.
I think that the problem is not use the app:itemBackground property, but the color that you set as itemBackground.
If I change my app:itemBackground color to white, it works fine, and I can show the shadow above and bottom of the BottomNavigationView. But if I use my primary color (blue), I can see the shadow only on the bottom of my BottomNavigationView.
I think that the easiest way to solve this problem, is create your own shadow and set it above of your BottomNavigationView. It's very simple. This post describes what you have to do.
If you encounter some problems, let a comment below.
I hope that this answer can help you!!
Good luck!!

Change Color TabSelector on v4 ViewPager

Is it possible to change color of selected tab on v4 ViewPager?
I need to use v4 ViewPager, but I don't find any source to customize it.
Just to clarify I need to change the blue color to another one:
This is the tab indicator. You can change its color by applying different styles.
Use Action Bar Style Generator, generate 9patch png files (tab_selected, tab_selected_focused etc.) and add these files + styles to your project.
Another approach -> How to change the current tab highlighter color in Android ViewPager? (as #Pratik wrote in comment).
I don't have enough reputation to comment on an Answer, but regarding the Action Bar Style Generator make sure after you add the files to the corresponding folders in your project that you also add the theme to your manifest xml file like this:
<activity
android:name="com.whatever.myapplication.YourActivityName"
android:theme="#style/Theme.Whatever_you_named_your_style_in_the_generator">
</activity>
The ViewPager is not the one you need to customize. You need to set the tabIndicatorColor of the TabLayout linked with it in the layout.
Dynamically you could do
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout_id);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setSelectedTabIndicatorColor(R.color.your_color); // here
Inside the XML, that would be as simple as the following
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#color/your_color" />
Same way i don't find the way to customize the tab. So i have fixed it using
<View
android:layout_height="2dp"
android:id="#+id/line1"
android:layout_width="fill_parent"
android:layout_below="#+id/headertab1"
android:layout_above="#+id/viewpager"
android:background="#0066CC" />
I have put this code with each 3 tabs belove the tab & above viewPager.
As we can detect that which tab is selected very easily.
So we can use this 'line1' visibility to View.VISIBLE or View.INVISIBLE.
Hope it helps to you!!

Android TabWidget default style

I have a problem that sounds like this:
I have a TabHost and I want to change it's size (height and width) so I used inflate to do this
TextView tabContent = (TextView)getLayoutInflater().inflate(R.layout.tab_content,tab.getTabWidget(),false);
and my xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab_label"
android:layout_width="80dp"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="14sp"
android:background="#color/green"
/>
This is working, but the problem is:
How do I inherit the old style of the tab since this is canceling it.
I mean i want this to be on the grey background and if i click it, to take focus and be yellow and so on, like the default tabs?
Thanks
Arkde
When you coose to customize your tabs, the standard tab behaviour is not accessible anymore.
Here is a very good example about customizing Tabs:
http://joshclemm.com/blog/?p=136

Categories

Resources