How to display text below icon in option menu? - android

Does anyone have an idea about how to customize the options menu item?. so I need to change display text below icon of the option menu item in a toolbar.

Use Custom toolbar :-
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorWhite"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/back_imageView"
android:layout_width="#dimen/card_h"
android:layout_height="#dimen/card_h"
android:layout_centerVertical="true"
android:contentDescription="#string/app_name"
android:paddingBottom="#dimen/small_margin"
android:paddingRight="#dimen/med_margin"
android:paddingTop="#dimen/small_margin"
android:src="#mipmap/back" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<ImageView
android:id="#+id/right_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/iv_dob"
android:layout_gravity="center"
android:contentDescription="#string/app_name" />
<TextView
android:id="#+id/first_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/lato_bold"
android:text="#string/app_name"
android:textAllCaps="true"
android:textColor="#color/colortext"
android:textSize="#dimen/normal_text_size" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>

You can use custom action Layout and put into menu Item:
Here is XML for menu.
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Eventapp="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_create"
android:actionLayout="#layout/action_view_details_layout"
android:orderInCategory="50"
android:showAsAction = "always"/>
</menu>
The Layout is
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="#string/create"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:src="#drawable/icon"/>
</LinearLayout>
this will show the icon and the text in vertical fashion.

Related

Layout design over navigation action bar

I am looking for a solution to design an element on the top of the navigation action bar and also a way to increase the size of the action bar. One way I can think of, is to disable the navigation action bar and then design. Is there any way if it's achievable without disabling the action bar?
Here is the design template:
just to be clear i am looking for an idea to design connect tab where one half is on the navigation action bar while other is on scroll view
xml for main
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:background="#696969">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:background="#696969">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Filter"
android:layout_marginLeft="20dp"
android:textSize="26sp"
android:textColor="#color/white"
>
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="scan"
android:textSize="26sp"
android:layout_marginLeft="20dp"
android:textColor="#color/white"
>
</Button>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
here is xml for toolbar
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/backkground">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:background="#color/black">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:padding="2dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:src="#drawable/ic_baseline_cast_connected_24">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:text="Connected"
android:textSize="44sp">
</TextView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
I am afraid i can show all the codes as its proprietry but i just wrote some to mitigate my current solution by dividing the background colo.lol.
After hard work of 30min. I got your answer. In your image, Toolbar is already in use with backButton, refreshButton, BluetothButton, and locationButton and they created the Connect button in TabLayout that's why it shows half on TabLayout and half on Blank Spaces.
I created it as shown in the template.
This is my XML layout code.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Your ToolBar Code or Other Code-->
<TableLayout
android:id="#+id/myTooBar"
android:layout_width="match_parent"
android:layout_gravity="top"
android:layout_height="?actionBarSize">
<!-- Here is sample textView with color-->
<TextView
android:background="#color/purple_500"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</TableLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
app:cardCornerRadius="15dp"
app:cardElevation="10dp"
app:layout_anchor="#+id/myTooBar"
app:layout_anchorGravity="bottom|center"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="#color/white"
android:padding="15dp"
android:gravity="left"
android:text="#string/connect"
android:textColor="#color/gray"
android:textSize="22sp"
android:textStyle="bold"
app:drawableLeftCompat="#drawable/ic_baseline_cell_wifi_24"
app:drawableTint="#color/gray" />
</androidx.cardview.widget.CardView>
<!-- Your more code of Activity-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
and this is the result
I hope it'll help you.
EDIT -1: Added more radius to cardView

Fix toolbar at the top while pressing enter in EditText in a fragment

There is a fragment with an EditText in it, and I want to show a toolbar fixed at the top in this fragment.
I want this toolbar to show up at the top regardless of how many times I press enter on the EditText, but now it just scrolls up and disappears.
How do I solve this?
This is the layout file of the fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#android:color/white"
tools:context=".MemoFragment">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/memo_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:layout_collapseMode="pin">
<Button
android:id="#+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_shape"
android:text="Confirm"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<EditText
android:id="#+id/memo_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/spacing_medium"
android:background="#drawable/text_shape"
android:fontFamily="sans-serif"
android:gravity="top" />
</RelativeLayout>
I have tried many of solutions found on StackOverflow but couldn't solve it.
Can anyone help me with this?
Thanks.
if you still cannot understand #Parul comments,
here is updated code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#android:color/white"
tools:context=".MemoFragment">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapseActionView"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="60dp">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/memo_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:layout_collapseMode="pin">
<Button
android:id="#+id/btn_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_shape"
android:text="Confirm"
android:textColor="#android:color/white"
android:textSize="#dimen/text_size_medium"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<EditText
android:id="#+id/memo_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/collapseActionView"
android:layout_marginLeft="#dimen/spacing_medium"
android:background="#drawable/text_shape"
android:fontFamily="sans-serif"
android:gravity="top" />
</RelativeLayout>
What happened here is you need to define specific locations in Relative layout otherwise later drawn/defined views (your edittext) will be shown above previous drawn views (your toolbar).

How to show the toolbar layout only when a song is played (ListView item is clicked)

activity_main2.xml
I want to show the toolbar in the following code only when a listView item is clicked. Otherwise, remain hidden. If I use (View.Invisible) in the Java Code then the layout disappears, yet white space remains in its area. I want the listview to occupy that area.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.ashutosh.music_player.Main2Activity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/catv" />
<ListView
android:id="#+id/track_list_view"
android:layout_width="match_parent"
android:layout_weight="100"
android:layout_height="0dp"
android:overScrollHeader="#drawable/catv1"/>
<android.support.v7.widget.Toolbar
android:id="#+id/bar_player"
android:background="#333333"
android:theme="#style/Theme.AppCompat.Dark.DarkActionBar"
android:layout_width="match_parent"
android:layout_height="50dp"
app:contentInsetStart="0dp">
<ImageView
android:id="#+id/selected_track_image"
android:layout_width="50dp"
android:layout_height="55dp" />
<TextView
android:id="#+id/selected_track_title"
android:paddingLeft="8dp"
android:layout_width="220dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/forward"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="30dp"/>
<ImageView
android:id="#+id/player_control"
android:layout_gravity="right"
android:layout_width="#dimen/image_size"
android:layout_height="#dimen/image_size" />
</android.support.v7.widget.Toolbar>
</LinearLayout>
Try this,This is what #shijil Said
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.ashutosh.music_player.Main2Activity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/catv" />
<ListView
android:id="#+id/track_list_view"
android:layout_width="match_parent"
android:layout_weight="100"
android:layout_height="0dp"
android:overScrollHeader="#drawable/catv1"/>
<android.support.v7.widget.Toolbar
android:id="#+id/bar_player"
android:background="#333333"
android:theme="#style/Theme.AppCompat.Dark.DarkActionBar"
android:layout_width="match_parent"
android:visibility="gone"
android:layout_height="50dp"
app:contentInsetStart="0dp">
<ImageView
android:id="#+id/selected_track_image"
android:layout_width="50dp"
android:layout_height="55dp" />
<TextView
android:id="#+id/selected_track_title"
android:paddingLeft="8dp"
android:layout_width="220dp"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/forward"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="30dp"/>
<ImageView
android:id="#+id/player_control"
android:layout_gravity="right"
android:layout_width="#dimen/image_size"
android:layout_height="#dimen/image_size" />
</android.support.v7.widget.Toolbar>
</LinearLayout>
and set programatically
.setVisibility(View.GONE);
.setVisibility(View.VISIBLE);
as needed
Simply use Relative Layout to do so. In this way, if you set the toolbar as invisible, the list view will occupy its position.

Android set full width on custom layouts for menu

I'm trying to attach custom layout for menu items on DrawerLayout, but as you see menu items don't have full width and i can't resolve this problem
My menu layout
<?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">
<group android:id="#+id/groupOne">
<item
android:id="#+id/inbox"
app:actionLayout="#layout/create_new"/>
</group>
</menu>
and my custom layout for that as create_new
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<TextView
android:layout_width="match_parent"
android:layout_height="25dp"
android:text="New Text"
android:gravity="left|center"
android:layout_marginLeft="20dp"
android:background="#000"
android:textColor="#fff"/>
</LinearLayout>
Yeah, the only way that worked for me was to set android:layout_width="100000dp" on the custom layout's root view.
Ugly ugly hack, however.
Add custom Spinner in Navigation menu / Navigation drawer / menu item.
1) Create Menu Item in menu directory.
<menu>
> <item
> android:id="#+id/navigation_drawer_item3"
> app:actionLayout="#layout/nav_drawer_home_spinner"
> tools:ignore="MenuTitle,icon" />
</menu>
2)Navigation drawer where you can put all types of navigation drawer
here.
- header
-menu with icon
-menu without icon
-custom menu item (Spineer)
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#color/md_white_1000"
tools:openDrawer="start">
<include
layout="#layout/app_bar_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dp"
android:background="#color/md_white_1000"
android:nestedScrollingEnabled="true"
android:layout_gravity="start">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical"
android:background="#color/md_white_1000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/md_white_1000">
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_with_icon"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:elevation="0dp"
android:background="#color/md_white_1000"
app:itemTextColor="#color/colorAccent"
app:itemIconTint="#color/colorAccent"
app:headerLayout="#layout/nav_header_dashboard"
android:theme="#style/NavigationViewStyle"
app:menu="#menu/activity_dashboard_drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_without_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/md_white_1000"
app:itemTextColor="#color/colorAccent"
android:elevation="0dp"
android:layout_gravity="bottom"
android:theme="#style/NavigationViewStyleOnlyText"
app:menu="#menu/activity_dashboard_withouticon_drawer"/>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_drawer_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
android:layout_gravity="bottom"
app:menu="#menu/activity_dashboard_spinner"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
3) Custom row_spinner_layout for putting your custom layout for menu
item of that navigation view.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_profilPic"
android:layout_width="0dp"
android:layout_weight="0.15"
android:layout_height="wrap_content"
android:padding="3dp"
android:src="#drawable/profilepic" />
     
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.7"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:orientation="vertical">
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/colorAccent"
android:text=""/>
<TextView
android:id="#+id/tv_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="#color/colorAccent"
android:text=""/>
</LinearLayout>
</LinearLayout>

Android Action Bar: Changing the color of Action Buttons and title to the center

Here an example
here is the pic please can any one suggest me how to change the icon colour and title to center to the action bar ...
Try this:
change pading if you want.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="#dimen/abc_action_bar_default_height_material">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_edit"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="ABC"
android:gravity="center"
android:layout_weight="1"
android:textColor="#android:color/white"
/>
<ImageView
android:layout_width="wrap_content"
android:paddingRight="10dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_edit"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Try like this.
Create new layout custom_toolbar.xml in your project.
Add below code in above file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imgLeft"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_events" />
<ImageView
android:id="#+id/imgRight"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_action" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Test"
android:textColor="#android:color/white"
android:textSize="25sp" />
</RelativeLayout>
And then add that layout to your toolbar xml file.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<include layout="#layout/custom_toolbar" />
</android.support.v7.widget.Toolbar>
Hope this will help you.

Categories

Resources