Android Imitation micro-letter bottom menu bar feature displays unread message quantity _android

Source: Internet
Author: User

The bottom menu bar is very important, I looked at a lot of applications are using the bottom menu bar, which uses the tabhost to do a generic (that is, you can display the number of unread messages like a micro-letter, although previously done but layout XML is too bloated, Here removed a lot of unnecessary layers, the individual looks good, so it is easy to post it for later use.
Take a look at what you've done before:


Later use the time can be replaced by their own project pictures and fonts, the main frame does not change haha,
The first is to lay out the layout XML file Main.xml:

<?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:layout_width= "fill_parent" android:layout_height= "Fill_parent" Android:backgrou nd= "@color/bg_gray" android:orientation= "vertical" > <framelayout android:id= "@android: Id/tabcont Ent "android:layout_width=" fill_parent "android:layout_height=" 0.0dip "android:layout_weight=" 1.0 "/& 
 
    Gt <tabwidget android:id= "@android: Id/tabs" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "0.0" android:visibility= "Gone"/> <framelayout and Roid:layout_width= "Fill_parent" android:layout_height= "Wrap_content" > <radiogroup android: Id= "@+id/main_tab_gRoup "android:layout_width=" fill_parent "android:layout_height=" Wrap_content "Android:layout_gr" avity= "Bottom" android:background= "@drawable/bottom1" android:gravity= "Bottom" android:orientat ion= "Horizontal" > <radiobutton android:id= "@+id/main_tab_addexam" style= "@style/mmtabbutton" android:layout_weight= "1.0" android:drawabletop= "@drawable/bg_checkbox_icon_m 
          Enu_0 "android:text=" add Quiz "/> <radiobutton android:id=" @+id/main_tab_myexam " style= "@style/mmtabbutton" android:layout_weight= "1.0" android:checked= "true" Androi 
          d:drawabletop= "@drawable/bg_checkbox_icon_menu_1" android:text= "My Exams"/> <radiobutton 
          Android:id= "@+id/main_tab_message" style= "@style/mmtabbutton" android:layout_weight= "1.0" android:drawabletop="@drawable/bg_checkbox_icon_menu_2" android:text= "my Notice"/> <radiobutton android:id= "@+id/main_tab_settings" style= "@style/mmtabbutton" android:layout_weight= "1.0" Android :d rawabletop= "@drawable/bg_checkbox_icon_menu_3" android:text= "Settings"/> </RadioGroup> &l T TextView android:id= "@+id/main_tab_new_message" android:layout_width= "Wrap_content" Android:lay out_height= "Wrap_content" android:layout_gravity= "Center_horizontal|top" android:layout_marginleft= "60di  
        P "android:layout_margintop=" 1dip "android:background=" "@drawable/tips" android:gravity= "center" android:text= "1" android:textcolor= "#ffffff" android:textsize= "10SP" Android:visibili 
 ty= "Gone"/> </FrameLayout> </LinearLayout> </TabHost>

Add a framelayout outside the Radiogroup, mainly in order to use TextView to display the number of messages, this is centered on the left 60dip, you may ask the direct written death can support multi-resolution, this I have tried on the 320*480 mobile phone is not a problem, Because the dip is a device-independent support multiresolution, as for the 1280*800 tablet computer such resolution I can not guarantee, haha!
Next is the style layout:

<style name= "Mmtabbutton" > 
  <item name= "android:textsize" >12.0dip</item> 
  <item name= " Android:gravity ">center_horizontal</item> 
  <item name=" Android:background "> @drawable/bg_ checkbox_menus</item> 
  <item name= "android:layout_width" >fill_parent</item> 
  <item Name= "Android:layout_height" >wrap_content</item> 
  <item name= "Android:button" > @null </item > 
  <item name= "Android:textcolor" > @color/white</item> 
  <item name= "Android:layout_weight ">1.0</item> 
  <item name=" Android:paddingbottom ">2.0dip</item> 
  <item name=" Android:paddingtop ">2.0dip</item> 

Under the drawable bg_checkbox_menus.xml

<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=  
"http://schemas.android.com/apk/res/" Android ">  
  <item  
  android:state_checked= false"  
  android:drawable= "@drawable/mm_trans"/>  
  <item  
  android:state_checked= "true"  
  android:drawable= "@drawable/home_btn_bg"/>  
</ Selector>  

The other four are all the same. Click the picture to change to bright color, so not one of them posted.
Finally see mainactivity this class:

Package cn.com.karl.test; 
Import android.app.TabActivity; 
Import android.content.Intent; 
Import Android.os.Bundle; 
Import Android.view.View; 
Import Android.view.Window; 
Import Android.widget.RadioGroup; 
Import Android.widget.RadioGroup.OnCheckedChangeListener; 
Import Android.widget.TabHost; 
 
Import Android.widget.TextView; The public class Mainactivity extends Tabactivity {/** called ' when the ' activity is ' is the ' the '. * Private created TA 
  Bhost; 
   
  Private TextView main_tab_new_message; 
    @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
    This.requestwindowfeature (Window.feature_no_title); 
     
    Setcontentview (R.layout.main); 
    Main_tab_new_message= (TextView) Findviewbyid (r.id.main_tab_new_message); 
    Main_tab_new_message.setvisibility (view.visible); 
     
    Main_tab_new_message.settext ("10"); 
    Tabhost=this.gettabhost (); 
    Tabhost.tabspec spec; 
 
    Intent Intent; Intent=new inTent (). SetClass (this, addexamactivity.class); 
    Spec=tabhost.newtabspec ("Add Quiz"). Setindicator ("Add Quiz"). SetContent (Intent); 
     
    Tabhost.addtab (spec); 
    Intent=new Intent (). SetClass (This,myexamactivity.class); 
    Spec=tabhost.newtabspec ("My Exams"). Setindicator ("My Exams"). SetContent (Intent); 
     
    Tabhost.addtab (spec); 
    Intent=new Intent (). SetClass (this, mymessageactivity.class); 
    Spec=tabhost.newtabspec ("my Notice"). Setindicator ("my Notice"). SetContent (Intent); 
     
    
    Tabhost.addtab (spec); 
    Intent=new Intent (). SetClass (this, settingactivity.class); 
    Spec=tabhost.newtabspec ("Settings"). Setindicator ("Settings"). SetContent (Intent); 
    Tabhost.addtab (spec); 
     
    Tabhost.setcurrenttab (1); 
    Radiogroup radiogroup= (Radiogroup) This.findviewbyid (R.id.main_tab_group); Radiogroup.setoncheckedchangelistener (New Oncheckedchangelistener () {@Override public void Onchecke Dchanged (radiogroup Group, int checkedid) {//TODO auto-generated metHod stub switch (checkedid) {case r.id.main_tab_addexam://Add exam Tabhost.setcurrenttabbytag ("Tim 
          Plus examination "); 
        Break 
          Case r.id.main_tab_myexam://My exam Tabhost.setcurrenttabbytag ("my Exams"); 
        Break 
          Case r.id.main_tab_message://My notice tabhost.setcurrenttabbytag ("my Notice"); 
        Break 
          Case r.id.main_tab_settings://Set Tabhost.setcurrenttabbytag ("Settings"); 
        Break 
          Default://tabhost.setcurrenttabbytag ("my Exams"); 
        Break 
  } 
      } 
    }); 
 } 
   
   
}

This completes, mainly uses the tabhost completes, Tabhost has the caching mechanism these four interfaces will cache in the memory, thus is advantageous also has the disadvantage, is advantageous because does not need to reload when the switch, has the disadvantage Because caching four of interfaces consumes more memory. If you only want to cache an interface, we can refer to this article: Android Project REAL-time imitation netease top navigation bar effect, using Activitygroup to achieve the top of the slide bar, like the top of NetEase news slide Bar I believe it is only cached an interface, switching time is from the database loaded, So the second slide load will be faster.

This article source download address: Android Imitation micro-letter bottom menu bar

The above is the entire content of this article, I hope to give you a reference, but also hope that we support the cloud habitat community.

Related Article

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.