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 ...
随机推荐
- 【ASP.NET基础】简单企业产品展示网站--产品编辑CRUD
摘要:本文记录创建一个小的.简单的产品网站的步骤. 一,搭建一个简单的产品展示网站,熟悉以下知识点:NVelocity模板引擎.Ajax无刷新页面请求,文件上传,Row_Number实现分页,ckEd ...
- css中常用的几种居中方法
在前端面试中,大都会问你div居中的方法: 文笔不好,就随便寥寥几句话概括了, 不过以后文笔肯定会变得更好一些的. 今天我们就细数一下几种方法: 1,使用position:absolute,设置lef ...
- Android—SDCard数据存取&Environment简介
1:Environment简介: Environment是android.os包下的一个类,谷歌官方文旦的解释为:Provides access to environment variables(提供 ...
- 简直喝血!H.265要被专利费活活玩死
转自 http://news.mydrivers.com/1/440/440145.htm H.264是如今最流行的视频编码格式之一,不但技术先进,而且专利费很低,企业每年只需支付650万美元,而个人 ...
- Java JPushV3服务端
因为JPush的官方文档太乱,所以依据原理自行实现. 主要技术就是post数据到https上和https的auth,实现起来还是很容易的. http://pan.baidu.com/s/1sjEc74 ...
- Part 98 Anonymous methods in c#
What is an anonymous method? Anonymous method is a method without a name. Introduced in C# 2.0,they ...
- text-overflow:ellipsis; 使用
ul li{ height:25px; line-height:25px; width:200px; overflow:hidden; white-space:nowrap;-moz-text-ove ...
- Iframe跨域_ASP.NET
1.描述: A系统 需要 调用 B系统的页面,被调用的B系统的页面b.html内部嵌套了iframe框架c.aspx地址页 2.问题呈现: ie浏览器下 Chrome浏览器下 追踪 3.问题原因: X ...
- php面向对象的特性:OOP的封装
字段的作用域: 1.public 公共的(类外可以访问) 2.private 私有的(只能类内访问) 3.protected 受保护的(类内和子类可以访问,类外无法访问) /*通过公共的方法来访问私有 ...
- 使用Hint来优化执行计划
最近看主管优化了一个HINT相关的查询 借此机会学习下HINT 参考Notes: Note 129385 - Database hints in Open SQL http://www.stechno ...