android sidebar navigation without using fragments - android

I want to create an activity that has sidebar on the left that is not changing between activity transitions (like split view in ios). It seems that I can do this with fragments but I need to add support for devices that is prior to HoneyComb.
I tried using a layout something like below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout android:layout_width="320dip"
android:layout_height="match_parent"
android:id="#+id/navLay"
>
<ListView
android:id="#+id/navList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/contentLay"
><ListView
android:id="#+id/contentList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</LinearLayout>
But the first list is also updated on activity transition. I want to note that the activity is the same activity except the right list's data source is different. So it would be pretty good if I could save state and content of the left navigation bar while navigating. Any help will be appreciated.

Take a look at Support Package which provides classes for backward compatibility, and includes Fragment class also.

It seems that I can do this with fragments but I need to add support for devices that is prior to HoneyComb.
You can use fragments and some new APIs on those devices. Just use support package.

Related

How to make a Navigation Drawer with these functionalities in Android?

I want to implement an Android app which measures someone's performances in sport activities.
The problem which I have is that I must implement a sliding menu from the left side of the screen, where one can change the account on which the performances must be registered.
I don't know how to make the part which is show in this picture.
One can add a new user by clicking on add new user button, can edit the account by clicking on the pen, and switch to other account by clicking on it when it is inactive.
I've searched for info about how to do this but I didn't find anything related to this.
This is how my app must look:
Does anyone have an idea about how to do this or something similar to my issue?
You have to Go for Sliding menu lib.
you can use android DrawerLayout.
Please take look.
There is Suggestion of design for NavigationDrawer..............
This could help you to Create Layout like that...
First Create Navigation Drawer form Here : Creating a Navigation Drawer
and then change some code in Drawelayout.xml(which contains nav. drawer)
navDrawer.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/com.equest.cwely.act"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/actionbar_bg"
android:orientation="vertical" >
<include
android:id="#+id/nav_list_header"
layout="#layout/nav_profile" />
<ListView
android:id="#+id/drawer_list"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="10dp"
android:choiceMode="singleChoice"
android:divider="#55ffffff"
android:dividerHeight="0.5dp"
android:listSelector="#drawable/list_selector" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Here,
<include/> : I have created one layout and added it into navDrawerLayout file...
<ListView/> : second Layout...........

layout_weight not working with LinearLayout inside Drawerlayout

I'm struggling with LinearLayout when using DrawerLayout. This is using the Android Studio template for DrawerLayout:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:background="#00f"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</LinearLayout>
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="#+id/navigation_drawer"
android:layout_width="#dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.test.testdrawerlayout.NavigationDrawerFragment"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
The preview in Android Studio shows this:
http://imgur.com/UlPGzJS
However, when running on my Nexus 5, the following shows:
http://imgur.com/w4QeGbB
As you can see, the layout_weight="1" part is not showing at all. When I create a blank project with the inner LinearLayout however, the layout works (with the blue layout taking most of the screen with the red layout at the bottom, just like the preview).
Any ideas would be really appreciated, as I'm completely stumped right now. Thanks in advance.
It appears I was using an older Android SDK platform. Once I went into SDK manager and installed API 19, it worked (with a new project).
Maybe it was a bug in an older implementation?
This is definitely an Android issue (or at least appcompat/design library issue). I've tested with different layouts inside the DrawerLayout, and concluded that the problem was "content_layout" file - the one that is displayed below the drawer.
Only using a clean, plain FrameLayout worked. No CoordinatorLayout, no fragments, no custom layouts nor 3rd-party layouts, just a good old FrameLayout with "match_parent" as width and height.
Inside the drawerlayout you should have a FrameLayout which contains the main content for your screen and you should also have a ListView in most cases to hold the contents of the navigation drawer.
It should be as such:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Now place your LinearLayout within the FrameLayout. Think of the FrameLayout as the "container" that holds your main screen.
Note that the official Android documentations state that
The main content view (the FrameLayout above) must be the first
child in the DrawerLayout because the XML order implies
z-ordering and the drawer must be on top of the content.
For more reference and information, I would advise you check this link by clicking here.
Please mark this as the answer if it solved your problem. Thank you.
UPDATE:
Okay first, remove "xmlns:android="http://schemas.android.com/apk/res/android"" from your linearlayout. That should only appear once and in the main root xml, in this cause the DrawerLayout.
Next, fix how you are using your weights. Declare a android:weightSum attribute. Think of weightSum as a pie. In this case we set it too 5, so we have 5 pieces of the pie. Anything inside this layout using the android:layout_weight attribute. This first one is set to 4, which will take 4/5ths of the screen. The last one is 1/5th of the screen at the bottom.
Make sure this LinearLayout is still wrapped within the FrameLayout. Your LinearLayout should appear as such:
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">
<LinearLayout
android:background="#00f"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"/>
<LinearLayout
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
</LinearLayout>
</LinearLayout>

Best way to implement tabs in android?

I have read looked through some code that implements tabs on the bottom of the app's page. And there is no deprecated method/class inside the code, and to me it is a very easy and clean way to implements tabs.
But I heard the new way of implementing tabs is to use fragments.
So, which one is better? And why?
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
android:id="#+id/edit_item_tab_host"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="65px" >
<LinearLayout
android:id="#+id/edit_item_date_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5px" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/edit_item_geocontext_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5px" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lieu"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/edit_item_text_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5px" >
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>
MainActivity class:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
// don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
tab_host.setup();
TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
ts1.setIndicator("tab1");
ts1.setContent(R.id.edit_item_date_tab);
tab_host.addTab(ts1);
TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
ts2.setIndicator("tab2");
ts2.setContent(R.id.edit_item_geocontext_tab);
tab_host.addTab(ts2);
TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
ts3.setIndicator("tab3");
ts3.setContent(R.id.edit_item_text_tab);
tab_host.addTab(ts3);
tab_host.setCurrentTab(0);
}
}
A TabHost cannot contain fragments (well, it can but it's really tricky) so I wouldn't recommend to use it today.
Fragments are the way to go, and if you want to implement the new Tab mechanism (which is integrated to the "new" ActionBar available on Android 3.0) and still support old android versions there is ActionBarSherlock, an open-source project which facilitate the use of the action bar design pattern across all versions of Android with a single API.
A lot of popular apps uses this project nowadays (including Google apps) so it's worth looking at.
A Fragment represents a behavior or a portion of user interface in an
Activity.
The android developer guide.
Your question seems to be worded a little strangely. You are asking about Tabs being at the bottom of the page but asking if you should use Fragments. Those are two different topics.
Yes, you should use Fragments, it is the route android is taking and will continue to take for the future.
Having Tabs at the bottom of the screen or at the top is a design decision. Depends on what would be more comfortable for the user experience, really doesn't have a lot to do with Fragments.
Google has introduced a new View called BottomNavigationView, a standard Bottom Navigation bar for android applications. As per guidelines you can add upto 5 (standard) items and pretty much simple as android's NavigationView.
Please do visit Component Guidelines, to know more about designing.

How to Use CustomSliding Drawer like Statusbar Notification in android App

am new to android apps am making an app Which has NFc technology,here i want to make a Notification bar like default OS statusbar Notification.
i made it custom now i want it to be call/display in all Screen while end user pull it from top to bottom within the app.
this is my custom Sliding drawer class and am using it in Main.xml file
<com.abc.xyx.customnotification.CustomDrawer
xmlns:my="http://schemas.android.com/apk/res/com.abc.xyx.app"
android:id="#+id/drawer"
my:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
my:handle="#+id/handle"
my:content="#+id/content"
android:layout_marginTop="100dp"
>
<include
android:id="#id/content"
layout="#layout/slider"/>
<ImageView
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="150px"
android:visibility="invisible"
android:src="#drawable/tooltiparea" />
</com.abc.xyx.customnotification.CustomDrawer>
You should google it up, there are quite a few samples with good explanation, like these:
Android SlidingDrawer with Custom View or
Example to implement
SlidingDrawer in XML or
Widget: SlidingDrawer top to bottom
you should use oops for that
first make a BaseActivity which extends android.app.Activity. Now this will be the parent Activity for all of your app's Activities where you want to display status bar. Define all the function related to custom status bar in that and a parent layout for holding views related to child Ativity
xml layout for BaseActivity will be like this
<com.abc.xyx.customnotification.CustomDrawer
xmlns:my="http://schemas.android.com/apk/res/com.abc.xyx.app"
android:id="#+id/drawer"
my:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
my:handle="#+id/handle"
my:content="#+id/content"
android:layout_marginTop="100dp"
>
<include
android:id="#id/content"
layout="#layout/slider"/>
<ImageView
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="150px"
android:visibility="invisible"
android:src="#drawable/tooltiparea" />
</com.abc.xyx.customnotification.CustomDrawer>
<RelativeLayout >
this layout is used for holding child Activities views
</RelativeLayout>
generate accesser method to access the slidingdrawer and parentLayout.
now your activities in which you want to add customSlidingBar should extends from BaseActivity in this way you only have to code once for sliding drawer implemation
hope it helps

iPhone- like tab bar in Android?

In iPhone we can create a view that has a tab bar and make it the root view of the application then use the tab bar to navigate through sub views.
what is the most close approach to this in Android?
Is it to use a Tabbed Control? but this includes using just one activity.
what is the approach to use in Android to create an activity with a navigation control to other activities in a way similar to that of the iPhone?
There's a tutorial for creating a "Tab Layout" on the android dev site:
You can implement your tab content in
one of two ways: use the tabs to swap
Views within the same Activity, or use
the tabs to change between entirely
separate activities
(source: android.com)
Sorry, I really don't know the iPhone, but may a QuickAction Dialog help you??
http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
I imagine a list of some activities in that dialog.
I hope this is close to what you want.
There are a couple of examples around
http://www.anddev.org/code-snippets-for-android-f33/iphone-tabs-for-android-t14678.html
This one is scrollable
http://code.google.com/p/mobyfactory-uiwidgets-android/
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="0dp"
>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</TabHost>

Categories

Resources