这一功能要用到动画相关知识

实现点击按钮弹出下方输入框,这里点击可弹出一个输入界面,其中包括一个小型计算器。

点击date可弹出datedialog设置date。

1、编写弹出框的布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="500dp"
>
<EditText
android:id="@+id/tv_tell"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/riple_btn_nocorner_3"
android:textColor="#212"
android:gravity="right"
android:hint="备注"
android:textColorHint="#B1A1A1"
android:textSize="30dp"></EditText>
<TextView
android:id="@+id/tv_cord"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/tv_tell"
android:background="@drawable/riple_btn_nocorner_3"
android:gravity="right"
android:textColor="#212"
android:hint="0"
android:textColorHint="#B1A1A1"
android:textSize="30dp"></TextView> <TextView
android:id="@+id/tv_calcul"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/tv_cord"
android:background="@drawable/riple_btn_nocorner_3"
android:textColor="#212"
android:gravity="right"
android:hint="0"
android:textColorHint="#B1A1A1"
android:textSize="30dp"></TextView>
<View
android:layout_width="match_parent"
android:layout_height="0.3dp"
android:background="#212"
></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tv_calcul"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" ><Button
android:id="@+id/calcul_btn_ac"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:fontFamily="宋体"
android:text="AC"
android:textSize="25dp"
android:layout_weight="2"
android:textColor="#169FDF"
></Button> <Button
android:id="@+id/calcul_btn_date"
android:layout_width="210dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:fontFamily="宋体"
android:text="date"
android:textAllCaps="false"
android:layout_weight="3"
android:textColor="#169FDF"
android:textSize="25dp"></Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="horizontal"
>
<Button
android:id="@+id/calcul_btn_1"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:fontFamily="宋体"
android:text="1"
android:layout_weight="1"
android:textColor="#169FDF"
android:textSize="25dp"></Button>
<Button
android:id="@+id/calcul_btn_2"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="2"
android:layout_weight="1"
android:textSize="25dp"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_3"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="3"
android:textSize="25dp"
android:textColor="#169FDF"
android:layout_weight="1"
android:fontFamily="宋体"></Button> <Button
android:id="@+id/calcul_btn_del"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="del"
android:textSize="30dp"
android:textColor="#169FDF"
android:layout_weight="2"
android:textAllCaps="false"
android:fontFamily="宋体"></Button> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="horizontal"
> <Button
android:id="@+id/calcul_btn_5"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="5"
android:textSize="25dp"
android:textColor="#169FDF"
android:layout_weight="1"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_6"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="6"
android:textSize="25dp"
android:textColor="#169FDF"
android:layout_weight="1"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_4"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="4"
android:textSize="25dp"
android:layout_weight="1"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_add"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="+"
android:textSize="25dp"
android:textColor="#169FDF"
android:fontFamily="宋体"
android:layout_weight="1"
></Button>
<Button
android:id="@+id/calcul_btn_multiply"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="×"
android:textSize="25dp"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="horizontal"
> <Button
android:id="@+id/calcul_btn_7"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_below="@id/calcul_btn_4"
android:layout_marginTop="0dp"
android:layout_toLeftOf="@id/calcul_btn_5"
android:background="@drawable/riple_btn_nocorner_3"
android:text="7"
android:textSize="25dp"
android:layout_weight="1"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_8"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_below="@id/calcul_btn_5"
android:layout_marginTop="0dp"
android:layout_toRightOf="@id/calcul_btn_7"
android:background="@drawable/riple_btn_nocorner_3"
android:text="8"
android:layout_weight="1"
android:textSize="25dp"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_9"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_below="@id/calcul_btn_6"
android:layout_marginTop="0dp"
android:layout_toRightOf="@id/calcul_btn_8"
android:background="@drawable/riple_btn_nocorner_3"
android:text="9"
android:layout_weight="1"
android:textColor="#169FDF"
android:textSize="25dp"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_sub"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="-"
android:textSize="25dp"
android:textColor="#169FDF"
android:layout_weight="1"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_divide"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:layout_weight="1"
android:text="÷"
android:textSize="25dp"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="horizontal"
>
<Button
android:id="@+id/calcul_btn_point"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_below="@id/calcul_btn_9"
android:background="@drawable/riple_btn_nocorner_3"
android:text="."
android:gravity="center"
android:textAllCaps="false"
android:layout_weight="1"
android:textSize="40dp"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
<Button
android:id="@+id/calcul_btn_0"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_below="@id/calcul_btn_8"
android:layout_marginTop="0dp"
android:layout_toRightOf="@id/calcul_btn_7"
android:background="@drawable/riple_btn_nocorner_3"
android:text="0"
android:textSize="25dp"
android:fontFamily="宋体"
android:layout_weight="2"
android:textColor="#169FDF"
></Button> <Button
android:id="@+id/calcul_btn_equal"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_below="@id/calcul_btn_divide"
android:layout_marginTop="0dp"
android:background="@drawable/riple_btn_nocorner_3"
android:text="完成"
android:textSize="20dp"
android:layout_weight="2"
android:textColor="#169FDF"
android:fontFamily="宋体"></Button>
</LinearLayout>
</LinearLayout>
</RelativeLayout>

  

2、编写一个Java类实现其弹出框中的各项功能,囊括一个接口使其在activity中实现

package com.example.didida_corder;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.icu.util.Calendar;
import android.icu.util.ChineseCalendar;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; //import java.util.Calendar;
import java.util.Date;
import java.util.zip.Inflater; import static java.lang.Math.sqrt; public class CalculFragment {
private Button btn_0, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9, btn_add,
btn_del, btn_mul, btn_ac, btn_sub, btn_equal, btn_divide, btn_date,
btn_point;
private TextView tv_cord, tv_calcul;
private double init = 0;//当前输入数据
private char calcul = '#';//运算符
private double nowsum = 0;//当前运算结果
private int pointnum = 0;//小数点输入次数
private RelativeLayout root;
private Context context;
boolean isaheadchar = false, isnowpoint = false, isaheadequal = false, isaheadsqr = false; //isaheadchar: 是否输入过运算符
//isnowpoint:小数点状态
//isaheadequal:前一个运算符是否为=
//isaheadsqr:前一个运算符是否为平方,主要为setText方便而设置
@RequiresApi(api = Build.VERSION_CODES.N)
public CalculFragment(RelativeLayout root, Context context) {
this.root = root;
this.context = context;
bindandset(this.root);
} @RequiresApi(api = Build.VERSION_CODES.N)
public RelativeLayout bindandset(View view) {
btn_0 = root.findViewById(R.id.calcul_btn_0);
btn_1 = root.findViewById(R.id.calcul_btn_1);
btn_2 = root.findViewById(R.id.calcul_btn_2);
btn_3 = root.findViewById(R.id.calcul_btn_3);
btn_4 = root.findViewById(R.id.calcul_btn_4);
btn_5 = root.findViewById(R.id.calcul_btn_5);
btn_6 = root.findViewById(R.id.calcul_btn_6);
btn_7 = root.findViewById(R.id.calcul_btn_7);
btn_8 = root.findViewById(R.id.calcul_btn_8);
btn_9 = root.findViewById(R.id.calcul_btn_9);
btn_date = root.findViewById(R.id.calcul_btn_date);
btn_point = root.findViewById(R.id.calcul_btn_point);
btn_sub = root.findViewById(R.id.calcul_btn_sub);
btn_ac = root.findViewById(R.id.calcul_btn_ac);
btn_add = root.findViewById(R.id.calcul_btn_add);
btn_equal = root.findViewById(R.id.calcul_btn_equal);
btn_del = root.findViewById(R.id.calcul_btn_del);
btn_divide = root.findViewById(R.id.calcul_btn_divide);
btn_mul = root.findViewById(R.id.calcul_btn_multiply);
tv_calcul = root.findViewById(R.id.tv_calcul);
tv_cord = root.findViewById(R.id.tv_cord);
tv_calcul.setText("");
tv_cord.setText("");
btn_0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
} else tv_calcul.setText(tv_calcul.getText() + "0");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("1");
} else tv_calcul.setText(tv_calcul.getText() + "1");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("2");
} else tv_calcul.setText(tv_calcul.getText() + "2");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("3");
} else tv_calcul.setText(tv_calcul.getText() + "3");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("4");
} else tv_calcul.setText(tv_calcul.getText() + "4");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("5");
} else tv_calcul.setText(tv_calcul.getText() + "5");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("6");
} else tv_calcul.setText(tv_calcul.getText() + "6");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("7");
} else tv_calcul.setText(tv_calcul.getText() + "7");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("8");
} else tv_calcul.setText(tv_calcul.getText() + "8");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal || isaheadchar) {
btn_equal.setText("=");
tv_calcul.setText("9");
} else tv_calcul.setText(tv_calcul.getText() + "9");
init = Double.parseDouble((String) tv_calcul.getText());
isaheadequal = false;
isaheadchar = false;
}
});
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { switch (calcul) {
case '+': {
nowsum += init;
break;
}
case '-': {
nowsum -= init; break;
}
case '*': {
nowsum *= init; break;
}
case '/': {
if (init != 0) {
nowsum /= init;
} else
break;
}
default: {
nowsum += init;
}
}
if (isaheadchar) {
if (!isaheadsqr)
tv_cord.setText(tv_cord.getText().subSequence(0, tv_cord.getText().length() - 1));
calcul = '+'; }
if (!isaheadequal) {
if (!isaheadchar)
tv_cord.setText(tv_cord.getText() + "" + init + "+");
else tv_cord.setText(tv_cord.getText() + "+");
tv_calcul.setText("" + nowsum);
} else {
tv_cord.setText("" + nowsum + "+");
tv_calcul.setText("" + nowsum);
}
calcul = '+';
init = 0;
isaheadequal = false;
isaheadchar = true;
isaheadsqr = false;
isnowpoint = false;
pointnum = 0;
}
});
btn_sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal) {
tv_cord.setText("");
}
switch (calcul) {
case '+': {
nowsum += init; break;
}
case '-': {
nowsum -= init; break;
}
case '*': {
nowsum *= init;
break;
}
case '/': {
if (init != 0) {
nowsum /= init;
} else
break;
}
case '士': {
nowsum *= -1;
break;
}
case '%': {
nowsum %= init;
break;
}
default: {
nowsum += init;
}
}
if (isaheadchar) {
if (!isaheadsqr)
tv_cord.setText(tv_cord.getText().subSequence(0, tv_cord.getText().length() - 1));
calcul = '-';
}
if (!isaheadequal) {
if (!isaheadchar)
tv_cord.setText(tv_cord.getText() + "" + init + "-");
else tv_cord.setText(tv_cord.getText() + "-");
tv_calcul.setText("" + nowsum);
} else {
tv_cord.setText("" + nowsum + "-");
tv_calcul.setText("" + nowsum);
}
calcul = '-';
init = 0;
isaheadequal = false;
isaheadchar = true;
isaheadsqr = false;
isnowpoint = false;
pointnum = 0;
}
});
btn_mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal) {
tv_cord.setText("");
}
switch (calcul) {
case '+': {
nowsum += init;
break;
}
case '-': {
nowsum -= init;
break;
}
case '*': {
nowsum *= init;
break;
}
case '/': {
if (init != 0) {
nowsum /= init;
} else
break;
}
case '士': {
nowsum *= -1;
break;
}
case '%': {
nowsum %= init;
break;
}
default: {
nowsum += init;
}
}
//if ptr calcul is calcul change it
if (isaheadchar) {
if (!isaheadsqr)
tv_cord.setText(tv_cord.getText().subSequence(0, tv_cord.getText().length() - 1));
calcul = '*';
}
if (!isaheadequal) {
if (!isaheadchar)
tv_cord.setText(tv_cord.getText() + "" + init + "×");
else tv_cord.setText(tv_cord.getText() + "×");
tv_calcul.setText("" + nowsum);
} else {
tv_cord.setText("" + nowsum + "×");
tv_calcul.setText("" + nowsum);
}
calcul = '*';
init = 0;
isaheadchar = true;
isaheadequal = false;
isaheadsqr = false;
isnowpoint = false;
pointnum = 0;
}
});
btn_divide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal) {
tv_cord.setText("");
}
switch (calcul) {
case '+': {
nowsum += init;
break;
}
case '-': {
nowsum -= init;
break;
}
case '*': {
nowsum *= init;
break;
}
case '/': {
if (init != 0) {
nowsum /= init;
} else
break;
}
case '士': {
nowsum *= -1;
break;
}
case '%': {
nowsum %= init;
break;
}
default: {
nowsum += init;
}
}
if (isaheadchar) {
if (!isaheadsqr)
tv_cord.setText(tv_cord.getText().subSequence(0, tv_cord.getText().length() - 1));
calcul = '/';
}
if (!isaheadequal) {
if (!isaheadchar)
tv_cord.setText(tv_cord.getText() + "" + init + "÷");
else tv_cord.setText(tv_cord.getText() + "÷");
tv_calcul.setText("" + nowsum);
} else { tv_cord.setText("" + nowsum + "÷");
tv_calcul.setText("" + nowsum);
}
calcul = '/';
init = 0;
isaheadequal = false;
isaheadchar = true;
isaheadsqr = false;
isnowpoint = false;
pointnum = 0;
}
});
btn_point.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_calcul.setText(tv_calcul.getText() + ".");
isnowpoint = true;
}
});
btn_equal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isaheadequal) {
tv_cord.setText("");
}
switch (calcul) {
case '+': {
nowsum += init;
break;
}
case '-': {
nowsum -= init;
break;
}
case '*': {
nowsum *= init; break;
}
case '/': {
if (init != 0) {
nowsum /= init;
} else
break;
}
case '士': {
nowsum *= -1;
break;
}
case '%': {
nowsum %= init;
break;
}
default: {
nowsum = init;
}
}
if (!isaheadsqr)
tv_cord.setText(tv_cord.getText() + "" + init + "=");
else tv_cord.setText(tv_cord.getText() + "=");
tv_calcul.setText("" + nowsum);
calcul = '#';
init = 0;
btn_equal.setText("完成");
isaheadequal = true;
isaheadsqr = false;
isnowpoint = false;
pointnum = 0;
}
});
btn_ac.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv_calcul.setText("");
tv_cord.setText("");
calcul = '#';
init = 0;
nowsum = 0;
isaheadchar = false;
isnowpoint = false;
isaheadequal = false;
isaheadsqr = false;
pointnum = 0;
}
});
btn_del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tv_calcul.getText().length() != 0)
tv_calcul.setText(tv_calcul.getText().subSequence(0, tv_calcul.getText().length() - 1));
}
});
final Calendar calendar = Calendar.getInstance();
String time = "" + calendar.get(Calendar.YEAR) + "/" + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DAY_OF_MONTH);
btn_date.setText(time);
btn_date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar1=ChineseCalendar.getInstance();
DatePickerDialog datePickerDialog=new DatePickerDialog(context, AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
btn_date.setText(""+year+"/"+month+"/"+dayOfMonth);
}
}, calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH), calendar1.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show();
}
});
return (RelativeLayout) view;
}
}

  

3、在Activity中实现2中的接口

public void send(int n) {
Dialog mCameraDialog = new Dialog(this, R.style.BottomDialog);
RelativeLayout root = (RelativeLayout) LayoutInflater.from(this).inflate(
R.layout.layout_fragment_calcul, null);
CalculFragment calculFragment=new CalculFragment(root,MainActivity.this);
root=calculFragment.bindandset(root);
mCameraDialog.setContentView(root);
Window dialogWindow = mCameraDialog.getWindow();
dialogWindow.setGravity(Gravity.BOTTOM);
dialogWindow.setWindowAnimations(R.style.DialogAnimation); // 添加动画
WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
lp.x = 0; // 新位置X坐标
lp.y = 0; // 新位置Y坐标
lp.width = (int) getResources().getDisplayMetrics().widthPixels; // 宽度
root.measure(0, 0);
lp.height = root.getMeasuredHeight();
// lp.alpha = 9f; // 透明度
dialogWindow.setAttributes(lp);
mCameraDialog.show();
}

  style

<style name="BottomDialog" parent="@android:style/Theme.Dialog">

        <!-- 背景透明 -->
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<!-- 浮于Activity之上 -->
<item name="android:windowIsFloating">true</item>
<!-- 边框 -->
<item name="android:windowFrame">@null</item>
<!-- Dialog以外的区域模糊效果 -->
<item name="android:backgroundDimEnabled">true</item>
<!-- 无标题 -->
<item name="android:windowNoTitle">true</item>
<!-- 半透明 -->
<item name="android:windowIsTranslucent">true</item>
<!-- Dialog进入及退出动画 -->
<item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>
<!-- ActionSheet进出动画 -->
<style name="DialogAnimation" parent="@android:style/Animation.Dialog">
<item name="android:windowEnterAnimation">@anim/dialog_in</item>
<item name="android:windowExitAnimation">@anim/dialog_out</item>
</style>

  

相关参考:

https://blog.csdn.net/lyp_1020k/article/details/79858982?utm_source=app

Android_下方弹出菜单的实现的更多相关文章

  1. iOS_21团购_顶部菜单和弹出菜单联动

    最后效果图: 各控件关系图1: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize ...

  2. 向上弹出菜单jQuery插件

    插件名:柯乐义英文名:Keleyijs文件名称:jquery.keleyi.js插件功能:该插件可以让你轻易地在页面上构建一个向上弹出的二级菜单. 示例查看:http://keleyi.com/kel ...

  3. html5手机端遮罩弹出菜单代码

    效果体验:http://hovertree.com/texiao/html5/17/ 效果图: 代码如下: <!doctype html> <html lang="zh&q ...

  4. DIV+CSS制作二级横向弹出菜单,略简单

    没有使用JavaScript控制二级菜单的显示,结果如上图所示. 代码如下: <!DOCTYPE html> <html> <head> <meta char ...

  5. vc++ 如何添加右键弹出菜单

    一.创建新工程 二.编辑菜单资源 1.添加菜单 按"Ctrl+R",双击"Menu"图标 2.于菜单编辑器内编辑菜单 四.添加代码(红色部分) void CCM ...

  6. 创建 iPhone/iOS8 弹出菜单(窗口)

    基本步骤 添加视图:主视图与弹出视图 关联视图 配置弹出视图 编码实现:弹出菜单样式及控制器委托 override func prepareForSegue(segue: UIStoryboardSe ...

  7. android 单选、多选弹出菜单

    菜单单选窗口: import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInte ...

  8. [Flex] PopUpButton系列 —— 弹出菜单的行高设置

    <?xml version="1.0" encoding="utf-8"?> <!--Flex中如何通过variableRowHeight样式 ...

  9. [Flex] PopUpButton系列 —— 控制弹出菜单的透明度、可用、可选择状态

    <?xml version="1.0" encoding="utf-8"?><!--控制弹出菜单的透明度.可用.可选择状态 PopUpButt ...

随机推荐

  1. Python 高级网络操作 - Python Advanced Network Operations

    Python 高级网络操作 - Python Advanced Network Operations Half Open Socket, 一个单向的 socket 被称为 half open sock ...

  2. qt creator源码全方面分析(2-10-4)

    目录 Plugin Life Cycle Plugin Life Cycle 为了能够编写Qt Creator插件,您必须了解启动或关闭Qt Creator时,插件管理器所采取的步骤. 本节详细描述插 ...

  3. k8s系列---yaml文件格式

    https://www.bejson.com/validators/yaml_editor/ yaml文件大致格式解析,通过上面这个解析网站,可以看到yaml文件解析的格式长什么样,如果知道字典和列表 ...

  4. 一起了解 .Net Foundation 项目 No.5

    .Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. Couchbase Lit ...

  5. 少量代码设计一个登录界面(二) – .NET CORE(C#) WPF开发

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. 阅读导航 本文背景 代码实现 本文参考 源码 1. 本文背景 同上篇文章<少量代码设计一 ...

  6. 医院信息集成平台(ESB)实施、建设方案

    医院信息集成平台(ESB)实施.建设方案 基于中立.标准.开放的IT架构和数据标准,打造插拔式医院应用生态. 解决方案 基于ESB集成总线,构建医院信息化建设顶层设计.                 ...

  7. 表关联使用INNER JOIN实现更新功能

    准备一些数据,创建2张表,表1为学生表: CREATE TABLE [dbo].[Student] ( [SNO] INT NOT NULL PRIMARY KEY, ) NOT NULL, ,) N ...

  8. 剑指offer-面试题66-构建乘积数组-发散思维

    /* 题目: 链接:https://www.nowcoder.com/questionTerminal/94a4d381a68b47b7a8bed86f2975db46 来源:牛客网 给定一个数组A[ ...

  9. clr via c# Array2

    1,Array类型生成方式以及实际类型 private static void ArrayIntro() { String[] sa = new String[1]; Array a1 = Array ...

  10. #《H.264和MPEG-4视频压缩》# 一. 色彩空间

    多数的数字视频应用需要播放彩色的视频信号,所以需要捕获和重现颜色信息.一幅黑白图像的每一个采样点只需要一个像素表示明暗或亮度,而在彩色图像中至少需要3个像素来表示每个像素的色彩.表示亮度和色彩的不同方 ...