android开发设置dialog的高宽
这里设置为跟屏幕一样的宽度,:看代码
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的高宽的更多相关文章
- iOS开发 UILabel实现自适应高宽
UILabel是iOS开发常用的控件.UILabel的属性需要了解,UILabel的特殊显示效果也需要我们掌握.UILabel自适应高宽度是很多初学者遇到的技术性难题.比如段文字,要让他完全地分行显示 ...
- Android开发——设置界面的创建
前言: 最近忙着搞项目,难得有时间,便来整理搞项目中学习到的知识 使用之前,先介绍一下android这种的五种数据储存方式,分别为文件储存,SharePrefence,SQL,使用ContentPro ...
- Android开发 - 设置DialogFragment全屏显示
默认的DialogFragment并不是全屏,但有些需求需要我们将对话框设置为全屏(内容全屏),Android并没有提供直接的API,通过其它不同的方法设置全屏在不同的机型上总有一些诡异的问题,经过测 ...
- 设置imageView正方形高宽
private void initWidth() { int screenWidth = ((MyApplication)getApplication()).screenWidth; if(0 == ...
- android 开发 对话框Dialog详解
转载请注明出处:红亮的专栏:http://blog.csdn.net/liang5630/article/details/44098899 Android中的对话框形式大致可分为五种:分别是一般对话框 ...
- android 开发-设置控件/view的水平方向翻转
设置控件沿着水平方向翻转(即Y轴180°) 看效果: 代码: <pl.droidsonroids.gif.GifImageView android:id="@+id/gv_image1 ...
- Android开发 设置开机自动启动
原文:http://blog.csdn.net/kevinmeng_ini58/article/details/7700786 片段一: <!-- 开机启动 --> <receive ...
- Android 开发 对话框Dialog dismiss和hide方法的区别
http://ningtukun.blog.163.com/blog/static/186541445201310151539697/ dismiss和hide方法都可以隐藏对话框,在需要的时候也可以 ...
- textarea 在不同浏览器高宽不一致的兼容性问题
在html,很多同学喜欢使用rows.cols,来设置textarea的高宽,却发现,在火狐跟其他浏览器,好像高宽却不一致! 因为这是火狐的一个bug, https://bugzilla.mozill ...
随机推荐
- EasyPusher推流服务接口的.NET导出
本文是在使用由 EasyDarwin 团队开发的EasyPusher时导出的C++接口的.NET实现 public class EasyPushSDK { public EasyPushSDK() { ...
- Android 百度地图开发(一)--- 申请API Key和在项目中显示百度地图
标签: Android百度地图API Key 分类: Android 百度地图开发(2) 最近自己想研究下地图,本来想研究google Map,但是申请API key比较坑爹,于是从百度地 ...
- JavaScript--DOM事件(笔记)
第1章 事件流1-1.事件冒泡:事件最开始由最具体的元素(文档中嵌套层次最深的那个节点)接收; 然后逐级向上传播至最不具体的那个节点(文档);1-2.事件捕获:不太具体的节点应该更早接收到事件,而最具 ...
- WIN7实用的运行命令
运行命令主要是DOS操作系统的运行方式.为方便用户的操作,微软公司将一些常用的命令,如DIR,CD等命令全部集成在系统里面:存放这些内部命令的文件是“Command”(文件后缀.com).它与IO.s ...
- Github 访问时出现Permission denied (public key)
一. 发现问题: 使用 git clone 命令时出现Permission denied (public key) . 二. 解决问题: 1.首先尝试重新添加以前生成的key,添加多次,仍然不起作用. ...
- IOS自定义场景切换动画。
IOS中我们可以通过Storyborad以及segue来实现我们自己的场景切换动画,新建项目使用Single View Application模板并取名为MyCustomSegue. 使用storyb ...
- 【学习笔记】【C语言】sizeof
1.用来计算一个变量或者一个常量.一种数据类型所占的内存字节数. 2.sizeof一共有3种形式 1>sizeof( 变量\常量 ) sizeof(10); char c = 'a'; size ...
- cpoint
#include<iostream> #include<math.h> using namespace std; class CPoint { public: int cpoi ...
- Android Studio添加jar包
1.先把jar包复制到项目的lib下,
- ASP.NET MVC 表单的几种提交方式
下面是总结一下在ASP.NET MVC中表单的几种提交方式. 1.Ajax提交表单 需要引用 <script type="text/javascript" src=" ...