这是XML布局

<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:background="@color/white"    android:orientation="vertical"    android:padding="10dp">            android:id="@+id/etCommentbox"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@color/wathet"        android:gravity="top"        android:hint="评论..."        android:maxLines="6"        android:minLines="6"        android:padding="10dp" />            android:id="@+id/tvComment"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="right"        android:layout_marginRight="10dp"        android:layout_marginTop="10dp"        android:background="@drawable/button_1"        android:paddingBottom="10dp"        android:paddingLeft="20dp"        android:paddingRight="20dp"        android:paddingTop="10dp"        android:text="评论"        android:textSize="15sp" />

然后是代码部分

   /**     * 弹出评论框     */    private void showCommentDailog() {        //R.style.***一定要写,不然不能充满整个屏宽,引用R.style.AppTheme就可以        final AlertDialog dialog = new AlertDialog.Builder(mContext, R.style.AppTheme).create();        View view = View.inflate(mContext, R.layout.commentbox_dialog, null);        Window window = dialog.getWindow();        window.setGravity(Gravity.BOTTOM);        //设置dialog弹出时的动画效果,从屏幕底部向上弹出        //window.setWindowAnimations(R.style.dialogStyle);//        window.getDecorView().setPadding(0, 0, 0, 0);        //设置dialog弹出后会点击屏幕或物理返回键,dialog不消失        dialog.setCanceledOnTouchOutside(true);        dialog.show();        window.setContentView(view);        //获得window窗口的属性        WindowManager.LayoutParams params = window.getAttributes();        //设置窗口宽度为充满全屏        params.width = WindowManager.LayoutParams.MATCH_PARENT;//如果不设置,可能部分机型出现左右有空隙,也就是产生margin的感觉        //设置窗口高度为包裹内容        params.height = WindowManager.LayoutParams.WRAP_CONTENT;        params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;//显示dialog的时候,就显示软键盘        params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;//就是这个属性导致window后所有的东西都成暗淡        params.dimAmount = 0.5f;//设置对话框的透明程度背景(非布局的透明度)        //将设置好的属性set回去        window.setAttributes(params);        EditText etCommentbox = (EditText) view.findViewById(R.id.etCommentbox);        TextView tvComment = (TextView) view.findViewById(R.id.tvComment);        tvComment.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                dialog.dismiss();            }        });    }

更多相关文章

  1. Android(安卓)PullToRefresh (ListView GridView 下拉刷新) 使用详
  2. 项目中平时遇到的小知识点集锦
  3. Android(安卓)ApiDemo 笔记(一)Content与Graphics
  4. Android(安卓)Studio 0.6.1 中 gradle 构建 异常
  5. 运行Android项目,报错java.lang.IllegalAccessException: access
  6. Android(安卓)View(四)-View相关属性详解
  7. Android隐藏输入法自带的输入框,将输入框向上推
  8. Android新手入门1
  9. 控制UI界面的方法

随机推荐

  1. Android中图片占用内存的计算
  2. Android 事件分发机制
  3. android中的sqlite数据库加密
  4. android source code online
  5. 在Android中使用Handler和Thread线程执行
  6. Android ImageView 总结【转载】
  7. Android ImageView图片显示点击背景切换
  8. android退出应用程序解决方案
  9. xmlns:android的作用
  10. Android定时器实现的几种方法