Activity implementation pop-up menu, activity pop-up menu
Activity is set to a dialog floating window and style, which can be used to complete functions that cannot be implemented by dialog. For example, the Activity can be suspended on the desktop of a mobile phone and is not affected by the activity interface, this indicates that the floating window is not affiliated with the Activity interface, that is, it is affiliated with the process of starting its application. For example, the application process where 360App is located disappears only when it is killed.
First:
1. java code:
MenuActivity. java
Package com. xiebao. aboutus; import android. OS. build; import android. OS. bundle; import android. view. gravity; import android. view. view; import android. view. window; import android. view. windowManager; import android. widget. textView; import com. xiebao. r; import com. xiebao. core. toastUtils; import com. xiebao. fatherclass. fatherActivity; public class MenuActivity extends FatherActivity implementsView. onClickListener {@ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. requestWindowFeature (Window. FEATURE_NO_TITLE); this. setContentView (R. layout. activity_menu_layout); setWindowAttribute (); initView ();} private void initView () {TextView back = getView (R. id. back_home); TextView about = getView (R. id. about_xiebao); TextView help = getView (R. id. help_center); TextView feed = getView (R. id. feed_back); back. setOnClickListener (this); about. setOnClickListener (this); help. setOnClickListener (this); feed. setOnClickListener (this);}/*** set window properties */private void setWindowAttribute () {if (Build. VERSION. SDK_INT> = 11) {setFinishOnTouchOutside (true);} // int heighted = ScreenUtil. getViewHeight (shareLayout); float mY = getResources (). getDimension (R. dimen. common_top_bar_height); Window window Window = getWindow (); WindowManager. layoutParams layoutParams = window. getAttributes (); // set the window size and transparency // layoutParams. width = WindowManager. layoutParams. MATCH_PARENT; // layoutParams. height = 48; layoutParams. gravity = Gravity. RIGHT | Gravity. TOP; layoutParams. y = (int) mY; // layoutParams. alpha = 0.5f; window. setAttributes (layoutParams);} @ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. back_home: break; case R. id. about_xiebao: break; case R. id. help_center: break; case R. id. feed_back: break; default: break;} finish (); ToastUtils. show (context, "nihao" + String. valueOf (v. getId ()));}}
2. layout file: activity_menu_layout.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/menu_color" android:gravity="center" android:orientation="vertical" android:padding="10dp" > <TextView android:id="@+id/back_home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/menu_backgroud_select" android:gravity="center" android:padding="10dp" android:text="@string/back_text" android:textColor="@color/white" android:textSize="20sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/list_divider_color" /> <TextView android:id="@+id/about_xiebao" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/menu_backgroud_select" android:gravity="center" android:padding="10dp" android:text="@string/about_xiebao" android:textColor="@color/white" android:textSize="20sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/list_divider_color" /> <TextView android:id="@+id/help_center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/menu_backgroud_select" android:gravity="center" android:padding="10dp" android:text="@string/help_center" android:textColor="@color/white" android:textSize="20sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/list_divider_color" /> <TextView android:id="@+id/feed_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/menu_backgroud_select" android:gravity="center" android:padding="10dp" android:text="@string/feed_back" android:textColor="@color/white" android:textSize="20sp" /></LinearLayout>
3. Style File: styles. xml
<Style name = "activity_dialog" parent = "@ android: style/Theme. Dialog"> <item name = "android: windowFrame"> @ null </item> <! -- Border --> <item name = "android: windowIsFloating"> true </item> <! -- Whether to float above activity --> <item name = "android: Movie wistranslucent"> true </item> <! -- Transparent --> <item name = "android: windowNoTitle"> true </item> <! -- No title --> <item name = "android: windowBackground"> @ null </item> <! -- Background transparency --> <item name = "android: backgroundDimEnabled"> false </item> <! -- This attribute can be translated to whether the background of the dialog box can be dimmed --> <item name = "android: windowAnimationStyle"> @ android: style/Animation. Translucent </item> </style>
4. configuration file: AndroidManifest. xml
<activity android:name=".aboutus.MenuActivity" android:launchMode="singleTask" android:screenOrientation="portrait" android:theme="@style/activity_dialog" > </activity>
End;
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.