Android drawer navigation, android drawer

Source: Internet
Author: User

Android drawer navigation, android drawer

Today I learned a simple android drawer navigation method.

Select when creating a project:

In this way, android IDE will give you a drawer navigation framework.

We only need to modify the following in the PlaceholderFragment class of MainActivity:

@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ){
View rootView = inflater. inflate (R. layout. fragment_main, container,
False );
TextView textView = (TextView) rootView. findViewById (R. id. section_label );
TextView. setText ("nth" + Integer. toString (getArguments (). getInt (ARG_SECTION_NUMBER) + "partial ");
Return rootView;
}

You can display the corresponding main interface according to etArguments (). getInt to the corresponding position.

The left navigation drawer interface is easier. We only need to modify the following items in the NavigationDrawerFragment class:

@ Override
Public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ){
MDrawerListView = (ListView) inflater. inflate (
R. layout. fragment_navigation_drawer, iner, false );
MDrawerListView
. SetOnItemClickListener (new AdapterView. OnItemClickListener (){
@ Override
Public void onItemClick (AdapterView <?> Parent, View view,
Int position, long id ){
SelectItem (position );
}
});
MDrawerListView. setAdapter (new ArrayAdapter <String> (getActionBar ()
. GetThemedContext (),
Android. R. layout. simple_list_item_activated_1,
Android. R. id. text1, new String [] {
GetString (R. string. title_section1 ),
GetString (R. string. title_section2 ),
GetString (R. string. title_section3 ),
GetString (R. string. title_section4 ),
GetString (R. string. title_section5 ),}));
MDrawerListView. setItemChecked (mCurrentSelectedPosition, true );
Return mDrawerListView;
}

This part is enough.

You can also create a general layout by modifying fragment_main.xml.

In this way, a simple navigation drawer is created.





How to enable Android mobile phone drawer

There are a lot of desktops, you can download and try it, but after a long time, I think there is nothing fun and inconvenient, my mobile desktop is simple just a few shortcut keys, other icons are hidden transparent, it is convenient, practical, and nice-looking. My desktop became more and more simple at the beginning, and I forgot to adopt it.

What is a tray and a drawer in the Android system? Can I give a legend? Thanks.

The tray is the position of the four icons at the bottom of the main interface of your mobile phone. The drawer is where you press the menu key to enter the place where you can see all the application icons.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.