Custom action bar in Android on top of everything is it possible? - android

Sorry for the question being too abstract but I really need fresh ideas.
I'm looking for a way to have multimedia keys, volume up and down and several other controls placed into an action bar in Android. Similar to the system action bar (with back and home button) I want the custom one to be visible all the time and on top of every other application's activity. The device to be used is rooted so this might make things easier. I specialize mostly in iOS development that's why I need your help.
Please if somebody has any idea please share it. I just need a direction to start.
EDIT: Sorry it seems like I haven't been understood correctly. What I meant is I want an action bar on top of every application. (Imagine the Facebook messanger's bubbles).
EDIT 2: Solution has been found: Creating a system overlay window (always on top)

First of all you should use ToolBar.
Create an xml file
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/CustomActionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageButton
android:id="#+id/vol_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_vol_plus_24dp"
/>
<ImageButton
android:id="#+id/vol_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_vol_minus_24dp"
/>
<ImageButton
android:id="#+id/vol_mute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_vol_mute_24dp"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Like this you can add controls in Toolbar and can attach in you activity
You can also layout for better view

yes you can have the action bar on top of the activity always just you ve to define the toolbar in the activity tht you arte goin to use.
// tool bar xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="#color/ColorPrimaryDark"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
//inisde the xml
<include
android:id="#+id/toolbar_action"
layout="#layout/toolbar" >
</include>
//activity class
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);

Related

How to make this bottom navigation bar?

Hello!
I just want to know if it's possible to make a bottom navigation bar like this, with this amazing blue center button. I just want the design (xml code). Can you help me?
Thanks!
I guess you can get the effect you want starting from this tutorial
then you have to work I guess the circle so that you can enlarge following another tutorial changing the size try this just to warm up and be confident for the concept, then you are going to find five solutions with the code here
<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>

Custom toolbar not appearing in preview tab

this is a very weird problem that I am facing for quite a lot of time. I was able to fix an issue which prevented any sort of widgets not appearing in an activity preview tab by adding "Base." to the theme. If I test it on my device, I can see my custom toolbar but in Android studio`s preview tab it all appears white. What I have tried:
1- Restarted Android studio
2- Invalidated caches and restarted Android studio
3- Changing app theme to different
toolbar.xml
<android.support.v7.widget.Toolbar 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="100dp"
android:background="#263238"
android:elevation="8dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<TextView
android:id="#+id/refToolbarTitleID"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEXT" />
</RelativeLayout>
I can not properly setup my toolbar. Any help is appreciated, thanks!
Your forgot to add </android.support.v7.widget.Toolbar> at the end of your XML.
I think you using the toolbar in a wrong way, you have to put the toolbar inside a root layout, just like you would do it with buttons or textviews, and then you have to pin it to the top side of the screen.

Header in android application with navigation menu

I am new to Android and I want to know how to best develop my app.
My app is going to be only on tablets and I have a navigation menu on the header (not side menu like a NavDrawer but a navigation menu on header like in websites).
The question is if it's better to make a header.xml file that contains all the navigation buttons and include it in every activity, and then in order to handle click events make it inside some base activity that every activity will inherit from.
Or it's better to make the header as a fragment and handle the click events inside the fragment itself.
Thanks.
Current practice is to use a Toolbar with either a navigation tab with a spinner or Tabs/Icons for each of your views. If you don't want to build this yourself you can use the TabbedActivity template when you set up your project.
The way it works is it's a Toolbar(new version of the ActionBar) included on the top of an Activity that has a fragment for the rest of the view. You can use a ViewPager or a FragmentManager to change the content of the fragment as the user makes his/her selection.
Here is the main activity of an app I built like this recently:
<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"
tools:context=".MainActivity"
android:background="#dfdfdf">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:layout_below="#id/tool_bar"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tabs"
/>
</RelativeLayout>
and the toolbar looks something like this:
<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="#color/colorPrimary"
android:elevation="6dp"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>

Using activity with drawer, scrolling toolbar, tabs and different fragments

I'm looking for best practices when it comes to the following pretty common setup:
What I'm currently doing is:
My Main Activity has a navigation drawer and a Toolbar.
When you click on one of the list items inside the drawer a fragment is loaded under the toolbar. Some fragments have their own tabs inside using viewpager ect.
I would like to make use of the material functionalities like hiding the toolbar while scrolling ect. It is no problem to get it done.
But there is a problem when only some of your fragments would like to make use of the scrolling toolbar. Using a normal Scrollview does solve the problem if you can add an additional margin at the bottom, but once you have a keyboard it will mess up as the scroll is wrong. Using a nestedscrollview works but does scroll the toolbar.
So how can I avoid the scrolling toolbar when my activity holds the toolbar and some fragments that scroll should make use of it and some not?
Is the architectural design wrong? Another thing I thought is to have the different toolbars inside of each fragment... but they have to share the same navigation drawer so you have to create and add the ToggleButton each time? Is it the right approach ? Should I go that path? I'm not convinced and would like to have the opinion of somebody more experienced then me. What's the best solution in this case.
Appreciate your help!
Cheers
EDIT:
Main Activity
<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">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_container_first"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="#+id/owner_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appBar"
android:orientation="horizontal"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/addicon"
app:fabSize="normal"
app:layout_anchor="#id/owner_main_container"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="xxx.Classes.Misc.ScrollAwareFABBehavior"
/>
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/drawerhost" />
I am also Using navigation drawer and tool bar please import project from this link
And try to understand how to use navigation drawer and tool bar using fragment

How to make fragment overlay toolbar in navigation drawer

I have a material design navigation drawer i created from this tutorial.
It works perfect with toolbar and all. I can click on an item in the drawer and the respective fragment is displayed plus the title.
However i would like to make the toolbar on one fragment to be transparent so that the background image is displayed like in the image below:
PROBLEM: My problem is the fragment doesnt seem to start over the toolbar but below it.This is the result:
I dont know how to fix this.Any suggestions will be welcomed.
Use this for toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/toolbar_image"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</FrameLayout>
Of course, you'll need to change "#drawable/toolbar_image" to the drawable that you want to use for the background image.

Categories

Resources