• Android PopupWindow底部菜单


     

    底部菜单实例

    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>
  • 相关阅读:
    李超线段树 (Li-Chao Segment Tree)
    NowCoder Contest 894
    AtCoder Beginning Contest 126
    华工软院IBM LinuxONE Community Cloud云计算实验文档
    Codeforces Round #561 (div. 2)
    Comet OJ Contest #3
    Codeforces Edu Round 65 (Rated for Div. 2)
    莫队算法 (Mo's Algorithm)
    Codeforces Round #559 (Div. 2)
    GDCPC2019 广东省赛总结
  • 原文地址:https://www.cnblogs.com/xuewater/p/2810315.html
Copyright © 2020-2023  润新知