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

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. 【CSS3】---@font-face

  2. 学习Slim Framework for PHP v3 (七)--route middleware怎么被add进来的?

    上两篇中分析了route是怎么被加进来的,以及如何被匹配的.这篇说一下route middleware是如何被加进来的,即add进来的.index.php的代码如下: $app->get('/f ...

  3. sql 了解

    char,varchar,nvarchar区别 类型 长度 使用说明 长度说明 char(n)  固定长度 索引效率高 程序里面使用trim去除多余的空白 n 必须是一个介于 1 和 8,000 之间 ...

  4. 解决 Oracle em 无法打开的问题

      重建em emca -deconfig dbcontrol db -repos drop 删除 emca -config dbcontrol db -repos create 创建 set ora ...

  5. Part 9 Sorting data in AngularJS

    To sort the data in Angular 1. Use orderBy filter     {{ orderBy_expression | orderBy : expression : ...

  6. Document.getElementById 与 $('#id')的区别

    一直认为jquery中的$("#id")和document.getElementByIdx_x("id")得到的效果是一样的,今天才发现并不是这么一回事,通过测 ...

  7. cocos2dx注册场景 使用CCEditBox实现输入框

    我们在开始玩一个游戏时,通常要做的第一件事就是注册账号,下面就让我们来制作一个简单的注册场景,我所使用的cocos2dx版本为2.2.2 在这个场景中最主要的元素就是输入框和按钮,我从网上找了一些素材 ...

  8. iOS 触摸的位置放一个大头针

    iOS 触摸的位置放一个大头针 UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self a ...

  9. asp.net 组织结构图控件

    记得之前做项目的时候客户需要看一个组织结构图,从而了解一下公司的概况,本来自己之前没有做过这方面的控件,只好找度娘,出于对项目的完美,网上很多控件画面感比较渣,后来只能在这些个中挑个比较好的来做,先看 ...

  10. 20150528—html使用Jquery遍历text文本框的非空验证

    <script src="jquery-1.7.2.min.js" type="text/javascript"></script> & ...