手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android Dialog 设置字体大小的具体方法
Android Dialog 设置字体大小的具体方法
摘要:先看下面图片:这是我在做登录页面的时候,调用系统的ProgressDialog进行等待,可是看起来很不协调,左边的等待图片过大,右边文字过小...

先看下面图片:

Android Dialog 设置字体大小的具体方法1

这是我在做登录页面的时候,调用系统的ProgressDialog 进行等待,可是看起来很不协调,左边的等待图片过大,右边文字过小,看起来老别扭,虽然功能上不存在什么问题,但是我有强迫症,看不顺的就像弄掉。可是找了好久,没发现 ProgressDialog 有一个方法是可以设置字体的。

于是我又来CSDN查找解决方案,可是找了好久,翻了好几页都没看到想要的结果,心冷了,找到的都说ProgressDialog 可以自定义一个View,在layout定义一个布局,然后设置到ProgressDialog 中,这确实是一个解决办法,可是对我来说颇显麻烦,我只是要一个等待效果,改一下字体,费不着去写一个layout,在重写一个ProgressDialog 吧。

最后我想想,可以设置ProgressDialog 的layout 那么应该也可以获取他的View吧,果然Dialog 就有一个获取View的方法:

复制代码 代码如下:

public abstract View getDecorView ()

Added in API level 1

Retrieve the top-level window decor view (containing the standard window frame/decorations and the client's content inside of that), which can be added as a window to the window manager.

Note that calling this function for the first time "locks in" various window characteristics as described in

只要有了View 我就可以找到其中的TextView,并设置相应的字体大小,一下是我的实现代码:

复制代码 代码如下:

/**

* 显示 进度对话框

* @param message 消息

* @param cancel 是否可取消

* @param textsize 字体大小

*/

protected final void showProgressDialog(String message,boolean cancel,int textsize)

{

// TODO Auto-generated method stub

mProgress = new ProgressDialog(this);

mProgress.setMessage(message);

mProgress.setCancelable(cancel);

mProgress.setOnCancelListener(null);

mProgress.show();

setDialogFontSize(mProgress,textsize);

}

private void setDialogFontSize(Dialog dialog,int size)

{

Window window = dialog.getWindow();

View view = window.getDecorView();

setViewFontSize(view,size);

}

private void setViewFontSize(View view,int size)

{

if(view instanceof ViewGroup)

{

ViewGroup parent = (ViewGroup)view;

int count = parent.getChildCount();

for (int i = 0; i < count; i++)

{

setViewFontSize(parent.getChildAt(i),size);

}

}

else if(view instanceof TextView){

TextView textview = (TextView)view;

textview.setTextSize(size);

}

}

最后看效果图:

Android Dialog 设置字体大小的具体方法2

【Android Dialog 设置字体大小的具体方法】相关文章:

android为按钮添加事件的三种方法

Android解决dialog弹出时无法捕捉Activity的back事件的方法

Android开发笔记 改变字体颜色的三种方法

基于Android中实现定时器的3种解决方法

Android控件系列之Shape使用方法

Android上网获取网络上的图片方法

Android判断包名和类名是否存在的方法

Android中将一个图片切割成多个图片的实现方法

android apk反编译到java源码的实现方法

Android 自定义标题栏 显示网页加载进度的方法实例

精品推荐
分类导航