"2015 Scientific research" 03 Android Development interface

Source: Internet
Author: User

Directory

    • Modify the icon and display text and overflow menu for Actionbar
    • tab and fragment loading layout
    • customizing themes with Style.xml
    • About the back key to return to the upper
    • Actionbar's Item
    • Current results
notes:
****************************** Target ******************************* ***************************************************************** 1. In the Androidmanifest.xml file, you can modify the Actionbar icon and display text. The items on the right overflow are set in the Main.xml in the menu folder:
1 <Menuxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Tools:context= "Com.example.mclock.MainActivity" >4     <Item5         Android:id= "@+id/action_settings"6 android:orderincategory= "1"7 android:showasaction="Never" 8 Android:title= "@string/action_settings"/>9     <ItemTen         Android:id= "@+id/action_about_us" One android:orderincategory= "2" A android:showasaction="Never"  - Android:title= "@string/action_about_us"> -     </Item> the </Menu>

Main activity Select Hide Return key:

  ActionBar ActionBar = getactionbar ();  Actionbar.setdisplayhomeasupenabled (false);

The return key display is:

  ActionBar ActionBar = getactionbar ();  Actionbar.setdisplayhomeasupenabled (true);

2. Style.xml and Androidmanifest.xml files, custom themes. ??? Underline blue I won't change color tab making reference: http://blog.csdn.net/guolin_blog/article/details/25466665

tab is a two-fragment.
fragment loading the layout , I think layout and code separation is more convenient, so use:

@Override        Public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {          = Inflater.inflate (r.layout.fixed_fragmentfalse);         return view;    }  
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical" >6     <TextView7         Android:id= "@+id/textview1"8 Android:layout_width= "Wrap_content"9 Android:layout_height= "Wrap_content"Ten Android:text= "fixed fragment!!!!" One android:layout_gravity= "Center"  A Android:background= "#ff0000"/> - </LinearLayout>

To implement this style, the XML code of the Style section ( This part is not very, I think it is to rewrite the source code of Android, and then the code hint seems to be nothing to use, so I press the CTRL key area source code to find a trial effect, it feels quite complicated): First of all, you should not forget to reference my custom theme in the Androidmanifest.xml file.
1 <Resourcesxmlns:android= "Http://schemas.android.com/apk/res/android">2 3     <stylename= "Apptheme"Parent= "@android: Style/theme.holo.light">4         <Itemname= "Android:actionbarstyle">@style/customactionbar</Item>5         <Itemname= "Android:actionbartabtextstyle">@style/customactionbartabtext</Item>6     </style>7 8     <stylename= "Customactionbar"Parent= "@android: Style/widget.holo.actionbar">9         <Itemname= "Android:windowactionbaroverlay">True</Item>Ten         <Itemname= "Android:titletextstyle">@style/actionbartitle</Item> One         <Itemname= "Android:background">#4abc96</Item> A         <Itemname= "android:backgroundstacked">#f5faf8</Item> -     </style> -  the     <stylename= "Actionbartitle"Parent= "@android: Style/textappearance.holo"> -         <Itemname= "Android:textcolor">@android: Color/white</Item> -     </style> -  +     <stylename= "Customactionbartabtext"Parent= "@android: Style/textappearance.holo"> -         <Itemname= "Android:textcolor">#3d3d3d</Item> +     </style> A  at </Resources>

3. About the back key to return to the upper level, Actionbar item:Http://zhidao.baidu.com/link?url=9zyLEjV41g_IRSmhajoSjJ5DilIXQDl2TjO00W2YTrhfKiOryMLkj9ZunXzr26h1haDo8idJSHg0xdY0u9Bwrq
 Public Booleanonoptionsitemselected (MenuItem item) {Switch(Item.getitemid ()) {Case   android. R.id.home: //The ID number of the back key finish (); return true;  Caser.id.action_tick:intent Intent=NewIntent (thirdactivity. This, Mainactivity.class);            StartActivity (Intent); return true; default:            return Super. onoptionsitemselected (item); }}

The alarm on the right is the item item that creates a new Second.xml in the menu folder.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Menuxmlns:android= "Http://schemas.android.com/apk/res/android" >3         <Item4         Android:id= "@+id/action_clock"  5 Android:icon= "@drawable/button_clock"  6 android:showasaction="Always"   7 Android:title= "@string/action_clock"/> 8 </Menu>

To load a menu in Java code:

 Public Boolean Oncreateoptionsmenu (Menu menu) {    getmenuinflater (). Inflate (r.menu.second, menu);     return true ;}
Current Results:    make a little look good happy ^ ^  

"2015 Scientific research" 03 Android Development interface

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.