Android. Toolbar menu doesn't show items - android

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

Related

I need to hide title of items in bottom navigation bar

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

Put SearchView on the right of back button icon

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

change position of items on the toolbar

i want to change the position of items of toolbar but im not found gravity
i hava menu_main.xml
<menu 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"
tools:context="haythamayyash.myapplication.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="2"
android:title="#string/action_settings"
app:showAsAction="never"/>
<item
android:id="#+id/backbutton"
android:orderInCategory="1"
android:title="back"
android:icon="#drawable/ic_action_name"
app:showAsAction="ifRoom"
/>
</menu>
and i have activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context="haythamayyash.myapplication.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
the items appear on the right side on the toolbar by default,
how can i change the position of items from right to left ?
app:showAsAction="never"
This will make the option hidden. It will be shown only when you click on the menu icon(3 dots on right top of the screen) or menu button of the phone.
app:showAsAction="always"
This will display the option always at the navigation bar.
android:orderInCategory="1"
This will decide the position/order of the option

Add Navigation Drawer to Exsisting Andrdoid Google Map

I'm developing Android Google Map project.
Here is what i wanted.
Default screen is like this and when drawer page must like this
I already did the google map part and I created a new Navigation Drawer Activity. How Am I suppose to connect these 2? I mean, how can I set the screen under the navigation drawer to my map page?
Already tried,
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.content_frame, new Fragment1());
tx.commit();
}
Did not work.
Please help. This may be a silly question. but, I'm new to Andrdoid.
Thanks
-Edit -
Here is the activity_maps.xml
<fragment 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"
android:id="#+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
Here is the activity_navigation.xml
<android.support.v4.widget.DrawerLayout
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:fitsSystemWindows="true">
<include layout="#layout/activity_maps"/>
<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/drawer"/>
Here is the drawer_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Abc"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
Here is the drawer.xml (menu)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
</group>
<item android:title="Sub items">
<menu>
</menu>
</item>
</menu>
I can not find what happened. But, I'm still getting the same error with this code.
Follow these steps.
Right click on your Android Studio project
Select New-> Activity -> Navigation Drawer Activity
Give a name and create the Navigation Drawer activity
open activity_drawer.xml
Add following code <include layout="#layout/activity_maps"/>
You'll get your answer
Hope this will help. :)

Android: layout issues, the layout is different in emulator than in preview

I am using android studio, but I do not know why it is showing the different layout in emulator. So I want an action bar in my layout but in emulator only blank layout is shown.
layout XML Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:id="#+id/listToDo"
android:weightSum="1">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list">
</ListView>
menu xml:
<menu 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"
tools:context=".MainActivity">
<item android:id ="#+id/home"
android:title ="home"
android:orderInCategory="100"
app:showAsAction ="ifRoom"/>
<item android:id="#+id/delete"
android:title="clear all"
android:orderInCategory="101"
app:showAsAction="ifRoom"/>
</menu>
In the preview, it shows the layout that i want to have. I am using Nexus 5 as an emulator

Categories

Resources