I create bottom navigation bar and i need to hide title and show icons only but when i write title with empty string there is big space between icon and bottom it just replace string with empty string and i make many search but i don't found solutions so any help
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.easyschools.student.HomeActivity">
<FrameLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/navigation"
android:layout_alignParentTop="true">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="#android:color/white"
android:layout_alignParentBottom="true"
app:menu="#menu/navigation"/>
</RelativeLayout>
navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/nav_messages"
android:icon="#drawable/msg_icon"
android:title=""/>
<item
android:id="#+id/nav_home"
android:icon="#drawable/home_icon"
android:title=""
android:checked="true"/>
<item
android:id="#+id/nav_notify"
android:icon="#drawable/notify_icon"
android:title=""/>
<item
android:id="#+id/nav_my_profile"
android:icon="#drawable/user_icon"
android:title=""/>
</menu>
Starting from support library 28.0.0-alpha1, you can use:
app:labelVisibilityMode="unlabeled"
to hide title and
app:itemHorizontalTranslationEnabled="false"
add:
xmlns:app="http://schemas.android.com/apk/res-auto"
to disable shift mode to your BottomNavigationView in xml
You can use following property of BottomNavigationView:
app:labelVisibilityMode="unlabeled"
also include following line in you layout:
xmlns:app="http://schemas.android.com/apk/res-auto"
For reference you can use following link:
https://www.11zon.com/zon/android/remove-bottom-navigation-view-title-in-android.php
The BottomNavigationView have a lot of limitations.
You can set the title with an empty String "" for example but I recommend you to use a library for enhancing the bottom navigation bar easily.
You can try this one : https://github.com/ittianyu/BottomNavigationViewEx
Related
Toolbar menu doesn't show items and I can't understand why. When I start VDA-emulator it's shows menu icon, but it's blank inside. Can't add screenshot, coz Stackoverflow has some promblems with servers, as it say.
Menu screen in VDA-emulator
Layout:
<LinearLayout 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"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
style="#style/ToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:menu="#menu/menu_toolbar"
app:navigationIcon="#drawable/ic_arrow_back"
app:title="#string/toolbar_name" />
</LinearLayout>
Menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="#string/toolbar_menu_1"/>
<item android:title="#string/toolbar_menu_2"
android:icon="#drawable/ic_comment"/>
</menu>
Current appcompact version 1.5.1
I created a navigation drawer in my app, but as you can see in the image above, the navigation drawer is too short and it is only long enough to contain the existing items.
My codes looks like:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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"
tools:context="ykim164cs242.tournamentor.UserMainActivity"
android:id="#+id/nav_layout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"></LinearLayout>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:menu="#menu/navigation_menu"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<group>
<item android:id="#+id/nav_select_channel"
android:title="Select Channel"
android:icon="#mipmap/channel_icon"/>
<item android:id="#+id/nav_team_list"
android:title="Team List"
android:icon="#mipmap/team_logo"/>
<item android:id="#+id/nav_league_status"
android:title="League Status"
android:icon="#mipmap/league_status_icon"/>
</group>
</menu>
I am not sure this happened because the background is dark, but I at least want it to fill the whole height of the app.
just make navigation view height to match_parent and width to wrap_content or give some value.
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/navigation_menu"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header">
I am trying to add navigation drawer to my main activity.
in design view of activity_main.xml it should be visible at left side of the activity layout as a shadowed animation(i don't know what terminology i should use here for that :| ),which on drag/swipe to right should be visible.
but in my case it is covering up the whole activity by default and is not displaying the actual contents of the activity ...which it ought to be...
i have gone through the solutionhere,but it is not working for me.
my layout code for activity_main.xml is as following:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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"
tools:context="com.example.mts3_.p1_d3_app_bar.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
android:id="#+id/app_bar"
layout="#layout/app_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/tv"
/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/drawer_menu"
/>
</android.support.v4.widget.DrawerLayout>
and drawer_menu.xml(layout file) is as following:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:title="#string/img1"
android:id="#+id/img11"
android:icon="#drawable/pic_1"></item>
<item android:title="#string/img2"
android:id="#+id/img22"
android:icon="#drawable/pic_2"></item>
<item android:title="#string/img3"
android:id="#+id/img33"
android:icon="#drawable/pic_3"></item>
<item android:title="#string/img4"
android:id="#+id/img44"
android:icon="#drawable/pic_4"></item>
</group>
<item android:title="#string/social">
<menu>
<item android:title="#string/add_to_group"
android:id="#+id/add_to_group"
android:icon="#drawable/pic_5"></item>
<item android:title="#string/share"
android:id="#+id/share"
android:icon="#drawable/pic_6"></item>
<item android:title="#string/group"
android:id="#+id/group"
android:icon="#drawable/pic_7"></item>
</menu>
</item>
</menu>
First,change your height and width android:layout_width="wrap_content" and android:layout_height="match_parent",
Second,set gravity android:layout_gravity="left" in your NavigationView.
Try this .
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
app:menu="#menu/drawer_menu"></android.support.design.widget.NavigationView>
Edit
If you use android:layout_gravity="left" in your xml code , you will start NavigationView on the left .
And android:layout_gravity="left" is the same of `android:layout_gravity="start``.
If you use android:layout_gravity="right" in your xml code , you will start NavigationView on the right.
And use tools:openDrawer="start" in your code ,it will display in the preview in the android studio .it did not effect your display in your device .
Put below Code in Drawerlayout tag
tools:openDrawer="start"
Like Following Code
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
After that implement that code in navigationView Tag
android:layout_gravity="start"
Hope it work fine.
So I am implementing a SearchView and right now I have two items in the layout. The back button and the search view.
I would like to know how can I make sure the back button appears on the left side of the screen before the search view, instead of the opposite.
This is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/back_btn"
android:title="#string/search"
app:icon="#drawable/ic_action_back_black"
android:icon="#drawable/ic_action_back_black"
app:showAsAction="ifRoom|collapseActionView"/>
<item android:id="#+id/search"
android:title="#string/search"
app:icon="#drawable/ic_search_black_24dp"
android:icon="#drawable/ic_search_black_24dp"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
I tried to put the back button before the search view, and it works fine until I click on the search box.
The Search view expands and the back button stays on the right side of the screen.
Question : Is there a way to make sure the back button will stay on the left side even when the search box expands?
This is the toolbar I am using:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/PopupMenuStyle"
android:id="#+id/my_awesome_toolbar"
android:layout_width="fill_parent"
android:layout_height="?android:attr/actionBarSize"
app:titleTextColor="#android:color/black"
android:layout_alignParentTop="true"
android:gravity="right"
android:elevation="5dp">
</android.support.v7.widget.Toolbar>
Hope this will help someone
First, make sure your activity not have an ActionBar
<item name="windowActionBar">false</item>
Second, add this code to your .xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="#+id/my_appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:padding="#dimen/margin_small">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-9dp"
android:layout_weight="6" />
<android.support.v7.widget.SearchView
android:id="#+id/my_search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/md_white_1000"
android:clickable="true"
android:focusable="true"
android:iconifiedByDefault="false" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
Last, set your back arrow programmatically
Display Back Arrow on Toolbar
inside search view tag add this attribute android:maxWidth
If the height of a NavigationView is less than the height of its parent, there's a drop shadow below the NavigationView. How can I remove that shadow?
Here's my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:layout_gravity="left"
android:orientation="vertical"
android:background="#android:color/white">
<android.support.design.widget.NavigationView
android:id="#+id/map_type_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
app:menu="#menu/menu_map_type"/>
<!-- unwanted drop shadow here -->
<fragment
android:id="#+id/settings"
android:name="com.chalcodes.treasuremap.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
I don't think this is relevant, but here's the menu_map_type XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/item_street"
android:icon="#drawable/ic_menu_map_type_street"
android:title="#string/map_type_street" />
<item
android:id="#+id/item_satellite"
android:icon="#drawable/ic_menu_map_type_satellite"
android:title="#string/map_type_satellite" />
<item
android:id="#+id/item_hybrid"
android:icon="#drawable/ic_menu_map_type_satellite"
android:title="#string/map_type_hybrid" />
<item
android:id="#+id/item_terrain"
android:icon="#drawable/ic_menu_map_type_terrain"
android:title="#string/map_type_terrain" />
</group>
</menu>
Just add to your NavigationView layout:
app:elevation="0dp"
The shadow is caused by the NavigationView having a non-zero default elevation. This was actually the first thing I thought of, but the way I tried to change it didn't work, so I mistakenly thought elevation wasn't the problem.
I originally added android:elevation="0dp" in the NavigationView declaration. This produced a warning because I'm supporting APIs below 21. I incorrectly assumed that this attribute would remain effective for API 21+, but apparently it gets stripped.
The solution was to set the elevation in code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
navView.setElevation(0f);
}
Try this.
<android.support.design.widget.NavigationView
android:id="#+id/map_type_menu"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
app:menu="#menu/menu_map_type">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<include layout="#layout/nav_header" />
<fragment android:id="#+id/settings" android:name="com.chalcodes.treasuremap.SettingsFragment" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.design.widget.NavigationView>