这里设置为跟屏幕一样的宽度,:看代码

dlg.show();
WindowManager.LayoutParams params = dlg.getWindow().getAttributes();
params.width = this.getWindowManager().getDefaultDisplay().getWidth();
// params.height = 200 ;
dlg.getWindow().setAttributes(params);

以下附上自定义dialog输入框代码:

import com.carspeak.client.R;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; /**
* 自定义弹出输入框
* Created by Administrator on 2014/12/11.
*/
public class CusInputDialog extends Dialog {
private EditText editText;
private Button positiveButton, negativeButton;
private TextView title;
public CusInputDialog(Context context) {
super(context, R.style.CusInputAlertDialog);
setCustomDialog();
}
private void setCustomDialog() {
View mView = LayoutInflater.from(getContext()).inflate(R.layout.view_dialog_input, null);
title = (TextView) mView.findViewById(R.id.title);
editText = (EditText) mView.findViewById(R.id.et_value);
positiveButton = (Button) mView.findViewById(R.id.positiveButton);
negativeButton = (Button) mView.findViewById(R.id.negativeButton);
super.setContentView(mView);
}
public View getEditText(){
return editText;
}
@Override
public void setContentView(int layoutResID) {
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
}
@Override
public void setContentView(View view) {
}
/**
* * 确定键监听器
* * @param listener
* */
public void setOnPositiveListener(View.OnClickListener listener){
positiveButton.setOnClickListener(listener);
}
/**
* * 取消键监听器
* * @param listener
* */
public void setOnNegativeListener(View.OnClickListener listener){
negativeButton.setOnClickListener(listener);
}
public void setTitle(String t)
{
title.setText(t);
}
public void setpositiveButtonTxt(String t)
{
positiveButton.setText(t);
}
public void setnegativeButtonTxt(String t)
{
negativeButton.setText(t);
}
}

style:

    <style name="CusInputAlertDialog" parent="@android:style/Theme.Dialog">  <!-- 带输入框的自定义弹出框样式 -->
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/bg_bombbox"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"> <TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="40.0dip"
android:gravity="center"
android:text="输入"
android:singleLine="true"
android:ellipsize="end"
android:textColor="#fff"
android:textSize="15sp" />
<EditText
android:id="@+id/et_value"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_marginTop="15dp"
android:gravity="left|center"
android:singleLine="true"
android:maxLength="200"
android:padding="1dp"
android:textColor="#333"/>
<!-- </LinearLayout> --> <LinearLayout
android:layout_width="match_parent"
android:layout_height="35.0dip"
android:layout_gravity="bottom"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal"> <Button
android:id="@+id/negativeButton"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textColor="#fff"
android:background="@drawable/selector_bt_gray2333"
android:gravity="center"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="取消"/> <Button
android:id="@+id/positiveButton"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="20.0dip"
android:textColor="#fff"
android:background="@drawable/selector_bt_blue2deeper"
android:gravity="center"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="确定"/>
</LinearLayout> </LinearLayout>

使用方法:

final CusInputDialog dlg = new CusInputDialog(this);
dlg.setTitle("请输入对应的语音命令");
dlg.setOnNegativeListener(new OnClickListener() { @Override
public void onClick(View arg0) {
dlg.dismiss();
}
});
dlg.setOnPositiveListener(new OnClickListener() { @Override
public void onClick(View arg0) {
String command_txt = ((EditText)dlg.getEditText()).getText().toString();
Log.v("CharInputActivity", "!RegexUtils.IsVoiceCommand(command_txt)="+!RegexUtils.IsVoiceCommand(command_txt));
if(!StringUtil.isNullorEmpty(command_txt)&&RegexUtils.IsVoiceCommand(command_txt))
{
// VoiceCommandEntity voice = new VoiceCommandEntity();
// voice.command = command_txt;
// voice.preViewUri = saveProjectionImage2File();
// saveProjectionImage2DB(voice);
// dlg.dismiss();
tv_shadow_preview.setDrawingCacheEnabled(true);
tv_shadow_preview.buildDrawingCache(); //启用DrawingCache并创建位图
Bitmap screen = Bitmap.createBitmap(tv_shadow_preview.getDrawingCache()); //创建一个DrawingCache的拷贝,因为DrawingCache得到的位图在禁用后会被回收
tv_shadow_preview.setDrawingCacheEnabled(false); //禁用DrawingCahce否则会影响性能
SaveVoiceCommandUtil sv = new SaveVoiceCommandUtil(CharInputActivity.this);
int rs = sv.saveVoiceCommand(command_txt, screen);
if(rs==1){Toast.makeText(CharInputActivity.this, "保存成功", Toast.LENGTH_SHORT).show();dlg.dismiss();}
else if(rs==0){Toast.makeText(CharInputActivity.this, "该命令已经存在", Toast.LENGTH_SHORT).show();}
else {Toast.makeText(CharInputActivity.this, "保存失败,错误码:"+rs, Toast.LENGTH_SHORT).show();}
}
else
{
Toast.makeText(CharInputActivity.this, "命令词只能是中英文和数字", Toast.LENGTH_SHORT).show();
} }
});
dlg.show();
WindowManager.LayoutParams params = dlg.getWindow().getAttributes();
params.width = this.getWindowManager().getDefaultDisplay().getWidth()-DensityUtils.dp2px(this, 40);
// params.height = 200 ;
dlg.getWindow().setAttributes(params);

android开发设置dialog的高宽的更多相关文章

  1. iOS开发 UILabel实现自适应高宽

    UILabel是iOS开发常用的控件.UILabel的属性需要了解,UILabel的特殊显示效果也需要我们掌握.UILabel自适应高宽度是很多初学者遇到的技术性难题.比如段文字,要让他完全地分行显示 ...

  2. Android开发——设置界面的创建

    前言: 最近忙着搞项目,难得有时间,便来整理搞项目中学习到的知识 使用之前,先介绍一下android这种的五种数据储存方式,分别为文件储存,SharePrefence,SQL,使用ContentPro ...

  3. Android开发 - 设置DialogFragment全屏显示

    默认的DialogFragment并不是全屏,但有些需求需要我们将对话框设置为全屏(内容全屏),Android并没有提供直接的API,通过其它不同的方法设置全屏在不同的机型上总有一些诡异的问题,经过测 ...

  4. 设置imageView正方形高宽

    private void initWidth() { int screenWidth = ((MyApplication)getApplication()).screenWidth; if(0 == ...

  5. android 开发 对话框Dialog详解

    转载请注明出处:红亮的专栏:http://blog.csdn.net/liang5630/article/details/44098899 Android中的对话框形式大致可分为五种:分别是一般对话框 ...

  6. android 开发-设置控件/view的水平方向翻转

    设置控件沿着水平方向翻转(即Y轴180°) 看效果: 代码: <pl.droidsonroids.gif.GifImageView android:id="@+id/gv_image1 ...

  7. Android开发 设置开机自动启动

    原文:http://blog.csdn.net/kevinmeng_ini58/article/details/7700786 片段一: <!-- 开机启动 --> <receive ...

  8. Android 开发 对话框Dialog dismiss和hide方法的区别

    http://ningtukun.blog.163.com/blog/static/186541445201310151539697/ dismiss和hide方法都可以隐藏对话框,在需要的时候也可以 ...

  9. textarea 在不同浏览器高宽不一致的兼容性问题

    在html,很多同学喜欢使用rows.cols,来设置textarea的高宽,却发现,在火狐跟其他浏览器,好像高宽却不一致! 因为这是火狐的一个bug, https://bugzilla.mozill ...

随机推荐

  1. Part 7 Joins in sql server

    Joins in sql server Advanced or intelligent joins in sql server Self join in sql server Different wa ...

  2. WebService 的创建,部署和使用

    WebService,即Web服务,能使得运行在不同机器上的不同应用无须借助,专门的第三方软件或硬件,就可相互交换数据或集成. 第一次选择WebService,是为了替代数据库远程连接.我们都知道当S ...

  3. C# lock用法

    当我们使用线程的时候,效率最高的方式当然是异步,即各个线程同时运行,其间不相互依赖和等待.但当不同的线程都需要访问某个资源的时候,就需要同步机制了,也就是说当对同一个资源进行读写的时候,我们要使该资源 ...

  4. 滚动视图和页面控制UIScollView,UIpageControlDemo

    ////  ViewController.m//  UIScollView////  Created by hehe on 15/9/25.//  Copyright (c) 2015年 wang.h ...

  5. jquery页面滚动,菜单固定到顶部

    // 菜单固定 $(function(){ //获取要定位元素距离浏览器顶部的距离 var navH = $("#topp").offset().top; //滚动条事件 $(wi ...

  6. 8个web前端的精美HTML5 & CSS3效果及源码下载

    作为一个前沿的 Web 开发者,对于 HTML5 和 CSS3 技术或多或少都有掌握.前几年这些新技术刚萌芽的时候,开发者们已经使用它们来小试牛刀了,如今这些先进技术已经遍地开发,特别是在移动端大显身 ...

  7. java随笔 乱腾腾的 一些东西

    调用requonse.getWriter()方法时可实现文本字符串数据输出,调用response.getOutputStream()方法可现实字节流数据的输出.两种输出方式threadlocal模式和 ...

  8. Fedora 20 创建桌面快捷方式

    创建desktop文件 sudo touch /usr/share/applications/sublime.desktop 添加内容 [Desktop Entry] Encoding=UTF-8 N ...

  9. WindowsMediaPlayer控件批量添加文件至播放列表

    思路: 1.读取批定路径的目录文件. 2.用List存放. 3.循环List列表添加到播放列表. public void VidieoPlay() { //WindowsMediaPlayer1.ui ...

  10. JS中的this用法详解

    随着对js的深入学习和使用,你会发现它里面包含了很多令人困惑的机制,比如对象.闭包.原型链继承等等,而这其中肯定包含令你现在或者曾经费解的this,如果你不把心一横,花点时间还真不明白这个this的用 ...