android dialog邊框去除白色邊框?qū)崿F(xiàn)思路及代碼
更新時間:2013年01月13日 17:04:05 作者:
android dialog邊框含有白色真是美中不足啊,本文將介紹如何去除白色邊框,有思路及代碼,感興趣的朋友可以了解下
使用樣式文件,在values 目錄下新建styles.xml文件,編寫如下代碼:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><resources>
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/black</item>
<item name="android:windowBackground">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
調(diào)用時,使用AlerDialog的接口類,Dialog 接口編寫如下代碼:
Dialog dialog = new Dialog(SetActivity.this, R.style.dialog);
dialog.setContentView(R.layout.test);
dialog.show();
下面我們查看一下Dialog的源碼文件,里面的構(gòu)造函數(shù)為如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public Dialog(Context context, int theme) {
mContext = new ContextThemeWrapper(
context, theme == 0 ? com.android.internal.R.style.Theme_Dialog : theme);
mWindowManager = (WindowManager)context.getSystemService("window");
Window w = PolicyManager.makeNewWindow(mContext);
mWindow = w;
w.setCallback(this);
w.setWindowManager(mWindowManager, null, null);
w.setGravity(Gravity.CENTER);
mUiThread = Thread.currentThread();
mDismissCancelHandler = new DismissCancelHandler(this);
}
這里面我們可以看出,Android 使用了默認的構(gòu)造函數(shù)為Dialog 設(shè)置樣式,如果沒有為其設(shè)置樣式,即默認加載事先編寫好的樣式文件,Dialog 一共由多個9.png的圖片構(gòu)成,大部分都是帶有邊框的9.png圖片,所以就是為什么我們上邊的樣式文件要將其背景去除掉。這個東西搞了我好久,希望對你有幫助
前后效果對比
復(fù)制代碼 代碼如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><resources>
<style name="dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/black</item>
<item name="android:windowBackground">@null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
調(diào)用時,使用AlerDialog的接口類,Dialog 接口編寫如下代碼:
復(fù)制代碼 代碼如下:
Dialog dialog = new Dialog(SetActivity.this, R.style.dialog);
dialog.setContentView(R.layout.test);
dialog.show();
下面我們查看一下Dialog的源碼文件,里面的構(gòu)造函數(shù)為如下:
復(fù)制代碼 代碼如下:
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public Dialog(Context context, int theme) {
mContext = new ContextThemeWrapper(
context, theme == 0 ? com.android.internal.R.style.Theme_Dialog : theme);
mWindowManager = (WindowManager)context.getSystemService("window");
Window w = PolicyManager.makeNewWindow(mContext);
mWindow = w;
w.setCallback(this);
w.setWindowManager(mWindowManager, null, null);
w.setGravity(Gravity.CENTER);
mUiThread = Thread.currentThread();
mDismissCancelHandler = new DismissCancelHandler(this);
}
這里面我們可以看出,Android 使用了默認的構(gòu)造函數(shù)為Dialog 設(shè)置樣式,如果沒有為其設(shè)置樣式,即默認加載事先編寫好的樣式文件,Dialog 一共由多個9.png的圖片構(gòu)成,大部分都是帶有邊框的9.png圖片,所以就是為什么我們上邊的樣式文件要將其背景去除掉。這個東西搞了我好久,希望對你有幫助
前后效果對比
未設(shè)置前:
設(shè)置后:
您可能感興趣的文章:
相關(guān)文章
解決Android BitmapFactory的基本使用問題
很多朋友給小編反饋使用方法BitmapFactory.decodeFile轉(zhuǎn)化Bitmap時報錯,究竟是什么原因?qū)е洛e誤問題呢?今天通過本文給大家介紹下解決Android BitmapFactory的基本使用問題,感興趣的朋友一起看看吧2021-10-10Android內(nèi)部存儲改變讀取權(quán)限的方法
今天小編就為大家分享一篇Android內(nèi)部存儲改變讀取權(quán)限的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

Android開發(fā)中Launcher3常見默認配置修改方法總結(jié)
這篇文章主要介紹了Android開發(fā)中Launcher3常見默認配置修改方法,結(jié)合實例形式分析了Android Launcher3的功能與配置修改相關(guān)操作技巧,需要的朋友可以參考下
2017-11-11 
Android手勢密碼--設(shè)置和校驗功能的實現(xiàn)代碼
這篇文章主要介紹了Android手勢密碼--設(shè)置和校驗功能的實現(xiàn)代碼,非常不錯,具有一定的參考校驗價值,需要的朋友可以參考下
2018-05-05 
Android利用SurfaceView實現(xiàn)簡單計時器
這篇文章主要為大家詳細介紹了Android利用SurfaceView實現(xiàn)一個簡單計時器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
2017-01-01