xamarin.android 实现 Activity 底部弹出对话框菜单

xamarin.android 实现 Activity 底部弹出对话框菜单_第1张图片

Resources/drawable 下新增如下文件:

push_bottom_in.xml

"1.0" encoding="utf-8" ?>

<set xmlns:android="http://schemas.android.com/apk/res/android" >

  <translate
      android:duration="200"
      android:fromYDelta="100%p"
      android:toYDelta="0"
     />
set>

push_buttom_out.xml

"1.0" encoding="utf-8" ?>

<set xmlns:android="http://schemas.android.com/apk/res/android" >
  <translate
      android:duration="200"
      android:fromYDelta="0"
      android:toYDelta="98%p" />
set>

 

在 values/Styles.xml 新增如下样式

  

  

新增如下文件 Resources/layout/LoginMenuPopupWindow.axml

"1.0" encoding="utf-8"?>
"http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical">
    <LinearLayout
        android:id="@+id/pop_layout"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:layout_alignParentBottom="true"
        android:background="#EEE"
        android:layout_width="match_parent">
        <Button
            android:id="@+id/btn_smsloginauthentication_loginmenupopupwindow"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="通过短信验证登陆"
            android:background="@drawable/v_line"
            android:textColor="@color/fonts_color" />
        <Button
            android:id="@+id/btn_changepassword_loginmenupopupwindow"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="修改密码"
            android:background="@drawable/v_line"
            android:textColor="@color/fonts_color" />
        <Button
            android:id="@+id/btn_cancel"
            android:layout_marginTop="10dip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="取消"
            android:textColor="@color/fonts_color"
            android:background="@drawable/top_line" />
    

对应的Activity 代码 LoginMenuPopupWindow.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using static Android.Views.View;

namespace Dorid
{
    [Activity(Theme = "@style/MyDialogStyleBottom")]
    public class LoginMenuPopupWindow : Activity, IOnClickListener
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.LoginMenuPopupWindow);

            var windowManager = WindowManager;
            var windowManagerLayoutParams = Window.Attributes;
            var displayMetrics = new Android.Util.DisplayMetrics();
            windowManager.DefaultDisplay.GetMetrics(displayMetrics);
            windowManagerLayoutParams.Width = (int)(displayMetrics.WidthPixels * 1); // 宽度设置
            Window.Attributes = windowManagerLayoutParams;

            var btn_cancel = FindViewById

 

转载于:https://www.cnblogs.com/mycing/p/5570167.html

你可能感兴趣的:(xamarin.android 实现 Activity 底部弹出对话框菜单)