Android PopupWindow底部菜单
2012-12-09 19:27
411 查看
import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.PopupWindow; public class MainActivity extends Activity { private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.arg1) { case 1: showBottomMenu(); break; } } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Timer timer = new Timer(); timer.schedule(new initBottomMenu(), 100); } private class initBottomMenu extends TimerTask { @Override public void run() { Message msg = new Message(); msg.arg1 = 1; handler.sendMessage(msg); } } /** * 显示底部菜单 */ public void showBottomMenu() { LayoutInflater mLayoutInfalter = (LayoutInflater) this .getSystemService(LAYOUT_INFLATER_SERVICE); View menuView = mLayoutInfalter.inflate(R.layout.menu, null); PopupWindow mPopupWindow = new PopupWindow(menuView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); mPopupWindow.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM, 0, 0); } }
主界面的布局文件:main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="底部菜单实例" /> </LinearLayout>
底部菜单的布局文件:menu.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" android:background="@drawable/menu_back"> <Button android:id="@+id/menu_ensureButton" android:layout_width="160px" android:layout_height="wrap_content" android:layout_marginTop="5px" android:text="完成" /> <Button android:id="@+id/menu_cancelButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="5px" android:text="取消" /> </LinearLayout>
相关文章推荐
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- Android PopupWindow实现右侧、左侧和底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- android PopupWindow底部弹出gridview菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- 【Android UI设计与开发】第09期:底部菜单栏(四)Fragment+PopupWindow仿QQ空间最新版底部菜单栏
- Android PopupWindow介绍及实现菜单效果
- android PopupWindow重写系统菜单
- 【Android UI设计与开发】第09期:底部菜单栏(四)Fragment+PopupWindow仿QQ空间最新版底部菜单栏
- Android27_OptionsMenu、ContextMenu及PopupWindow自定义菜单
- 【Android UI设计与开发】6.底部菜单栏(三)使用Fragment+PopupWindow仿QQ空间最新版底部菜单栏
- [置顶] Android:PopWindow — 对Android的底部弹窗、顶部弹窗菜单及自定义界面的使用封装
- PopupWindow实现右侧、左侧和底部弹出菜单
- Android之PopupWindow-底部弹出,以及中间弹出有变暗效果
- android中用PopUpWindow自定义Menu菜单 带半透明效果
- 【Android UI设计与开发】第09期:底部菜单栏(四)Fragment+PopupWindow仿QQ空间最新版底部菜单栏