Android Imitation micro-letter implementation dropdown list _android

Source: Internet
Author: User

This article will be implemented in the micro-letter 6.1 Click on the top menu bar "+" button, a list box pops up. Here is the activity to achieve, in fact, the best way to use Actionbar, but this product seems to support only 3.0 later version. This article is followed by the Android imitation micro-letter at the bottom of the menu bar + top menu bar .

Effect

First, imitation micro-letter Drop-down List Layout pop_dialog.xml

<?xml version= "1.0" encoding= "UTF-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Wrap_content "android:layout_height=" wrap_content "> <relativelayout androi D:layout_width= "Fill_parent" android:layout_height= "fill_parent" android:layout_margintop= "45DP" Android:layout_ marginright= "20DP" > <linearlayout android:id= "@+id/id_pop_dialog_layout" android:layout_width= "Wrap_content" "Android:layout_height=" Wrap_content "android:layout_alignparentright=" true "android:layout_alignparenttop=" true "Android:background=" @drawable/pop_item_normal "android:orientation=" vertical "> <linearlayout android:id = "@+id/id_groupchat" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:layout_ marginleft= "5DP" android:layout_marginright= "5DP" android:layout_margintop= "5DP" android:background= "@drawable Pop_list_selector "> <imageview androiD:id= "@+id/id_imageview1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout 
  _gravity= "center_vertical" android:layout_marginleft= "8DP" android:src= "@drawable/pop_group"/> <TextView Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:padding= "8DP" android:text= "hair Chat "android:layout_gravity=" center_vertical "android:textcolor=" #fff "android:textsize=" 16sp "/> </Linea rlayout> <imageview android:id= "@+id/id_imageview5" android:layout_width= "Wrap_content" Android:layout_hei ght= "Wrap_content" android:src= "@drawable/pop_line"/> <linearlayout android:id= "@+id/id_addfrd" android:l Ayout_width= "Fill_parent" android:layout_height= "wrap_content" android:layout_marginleft= "5DP" Android:layout_ marginright= "5DP" android:background= "@drawable/pop_list_selector" > <imageview android:id= "@+id/id_imagevi Ew2 "Android:layout_width="Wrap_content "android:layout_height=" wrap_content "android:layout_gravity=" center_vertical "Android:layout_margin" left= "8DP" android:src= "@drawable/pop_add"/> <textview android:layout_width= "Wrap_content" Android:lay out_height= "Wrap_content" android:padding= "8DP" android:text= "add Friend" android:layout_gravity= "Center_vertical" a Ndroid:textcolor= "#fff" android:textsize= "16sp"/> </LinearLayout> <imageview android:id= "@+id/id_i" MageView5 "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:src=" @drawable/pop_ Line "/> <linearlayout android:id=" @+id/id_find android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_marginleft= "5DP" android:layout_marginright= "5DP" android:background= "@drawable/pop _list_selector "> <imageview android:id=" @+id/id_imageview3 "android:layout_width=" Wrap_content "Androi" 
d:layout_height= "Wrap_content"  Android:layout_gravity= "center_vertical" android:layout_marginleft= "8DP" android:src= "@drawable/pop_qrcode"/> 
  <textview android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:padding= "8DP" android:text= "Sweep" android:layout_gravity= "center_vertical" android:textcolor= "#fff" android:textsize= "16SP"/ > </LinearLayout> <imageview android:id= "@+id/id_imageview5" android:layout_width= "Wrap_content" a ndroid:layout_height= "Wrap_content" android:src= "@drawable/pop_line"/> <linearlayout android:id= "@+id/id_fe 
 Edback "android:layout_width=" fill_parent "android:layout_height=" wrap_content "android:layout_marginbottom=" 3DP " android:layout_marginleft= "5DP" android:layout_marginright= "5DP" android:background= "@drawable/pop_list_selector "> <imageview android:id=" @+id/id_imageview4 "android:layout_width=" Wrap_content "Android:layout_heigh t= "Wrap_content" Android:layOut_gravity= "center_vertical" android:layout_marginleft= "8DP" android:src= "@drawable/pop_feedback"/> <Tex Tview android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:padding= "8DP" android:t Ext= "Help and Feedback" android:layout_gravity= "center_vertical" android:textcolor= "#fff" android:textsize= "16sp"/> ;/linearlayout> </LinearLayout> </RelativeLayout> </RelativeLayout>

Where to change the color after the picture is pressed:
android:background= "@drawable/pop_list_selector" >
Pop_list_selector.xml is as follows

<?xml version= "1.0" encoding= "UTF-8"?> <selector xmlns:android= 
"http://schemas.android.com/apk/res/" Android > 
 
 <item android:drawable= "@drawable/pop_item_pressed" android:state_focused= "true"/> 
 <item android:drawable= "@drawable/pop_item_pressed" android:state_pressed= "true"/> 
 <item android: drawable= "@drawable/pop_item_pressed" android:state_selected= "true"/> 
 <item android:drawable= "@ Drawable/pop_item_normal "/> 
 
</selector> 

Look at the effect, this is removed after the title bar (also can be removed by code)

To remove the title bar method:

Second, the corresponding code
Pop_dialog.xml the corresponding code is Popdialogactivity.java
As follows:

Package com.example.tabexample; 
Import android.app.Activity; 
Import Android.os.Bundle; 
Import android.view.MotionEvent; 
Import Android.view.View; 
Import Android.view.Window; 
Import Android.view.View.OnClickListener; 
 
Import Android.widget.LinearLayout; public class Popdialogactivity extends activity implements onclicklistener{//Definition four button area private LinearLayout mgroupchat 
 ; 
 Private LinearLayout MADDFRD; 
 Private LinearLayout Mfind; 
 
 Private LinearLayout Mfeedback; 
 @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 
 Requestwindowfeature (Window.feature_no_title); 
 
 Setcontentview (R.layout.pop_dialog); 
 Initview (); }/** * Initialization component/private void Initview () {//Get Layout Component object and set listener event Mgroupchat = (linearlayout) Findviewbyid (r.id.id_ 
 Groupchat); 
 MADDFRD = (linearlayout) Findviewbyid (R.ID.ID_ADDFRD); 
 Mfind = (linearlayout) Findviewbyid (R.id.id_find); 
 Mfeedback = (linearlayout) Findviewbyid (r.id.id_feedback);
 Mgroupchat.setonclicklistener (this); 
 Maddfrd.setonclicklistener (this); 
 Mfind.setonclicklistener (this); 
 Mfeedback.setonclicklistener (this); 
 @Override public boolean ontouchevent (Motionevent event) {finish (); 
 return true; 
 @Override public void OnClick (View v) {}}

Third, set the background transparent
If this is the case, when the activity comes out, it will overwrite the previous activity, but would it be possible to set it to a transparent background? The method is as follows:
Add in Androidmanifest.xml:

<!--This activity must be registered here, otherwise the jump will fail because the system cannot find the activity--> 
t;activity 
 android:name= " Com.example.tabexample.PopDialogActivity " 
 android:label=" @string/app_name " 
 android:theme=" @style Mydialogstyletop "> 

which
"@style/mydialogstyletop"
is my own defined format, added under Value/style:

<style name= "Mydialogstyletop" parent= "Android:Theme.Dialog" > 
 <item name= "Android:windowframe" >@ null</item><!--Border--> 
 <item name= "android:windowisfloating" >true</item> <!-- Whether it emerges above the activity--> 
 <item name= "android:windowistranslucent" >false</item><!--Translucent--> 
 <item name= "Android:windownotitle" >true</item> <!--untitled--> 
 <item "Android: Windowbackground "> @android:color/transparent</item><!--background transparent--> 
 <item name=" Android: backgrounddimenabled ">false</item><!--fuzzy--> 
</style> 

Four, use
in fact, use is the activity of the jump, the method is very simple, a sentence:
startactivity (New Intent (Mainactivity.this,popdialogactivity.class));
put this sentence in the "+" button in the click of the event, add here Click event is needless to say, very simple, and then the final effect is as follows:

This article has been organized into the "Android micro-credit Development tutorial Summary," Welcome to learn to read.

The above is the entire contents of this article, I hope to learn more about Android software programming help.

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.