欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Dialog 設(shè)置字體大小的具體方法

 更新時(shí)間:2013年09月16日 16:30:24   作者:  
這篇文章介紹了Android Dialog 設(shè)置字體大小的具體方法,希望能幫助到有同樣需求的朋友,可能我的方法不是最好的,也希望有朋友指點(diǎn)

先看下面圖片:

這是我在做登錄頁面的時(shí)候,調(diào)用系統(tǒng)的ProgressDialog 進(jìn)行等待,可是看起來很不協(xié)調(diào),左邊的等待圖片過大,右邊文字過小,看起來老別扭,雖然功能上不存在什么問題,但是我有強(qiáng)迫癥,看不順的就像弄掉。可是找了好久,沒發(fā)現(xiàn) ProgressDialog  有一個(gè)方法是可以設(shè)置字體的。

于是我又來CSDN查找解決方案,可是找了好久,翻了好幾頁都沒看到想要的結(jié)果,心冷了,找到的都說ProgressDialog 可以自定義一個(gè)View,在layout定義一個(gè)布局,然后設(shè)置到ProgressDialog 中,這確實(shí)是一個(gè)解決辦法,可是對(duì)我來說頗顯麻煩,我只是要一個(gè)等待效果,改一下字體,費(fèi)不著去寫一個(gè)layout,在重寫一個(gè)ProgressDialog 吧。

最后我想想,可以設(shè)置ProgressDialog  的layout 那么應(yīng)該也可以獲取他的View吧,果然Dialog 就有一個(gè)獲取View的方法:

復(fù)制代碼 代碼如下:

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,并設(shè)置相應(yīng)的字體大小,一下是我的實(shí)現(xiàn)代碼:

復(fù)制代碼 代碼如下:

    /**
     * 顯示 進(jìn)度對(duì)話框
     * @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);
        }
    }

最后看效果圖:

相關(guān)文章

最新評(píng)論