問題描述
我正在嘗試為我的應(yīng)用程序?qū)υ捒蛑谱髯远x對話框形狀.我一直在尋找這個主題幾個小時,但我找到的解決方案對我不起作用,這就是為什么我問你我自己的問題.我想要一個帶有圓角的對話框并顯示一個標(biāo)題,然后是一個帶有一些文本的 ScrollView.唯一對我不起作用的是圓角.在這里我把我的代碼貼給你:
I'm trying to make a custom dialog shape for my app's dialogs. I've been searching for this topic for hours, but the solutions I find don't work for me, that's why I ask you for my own problem. I want a Dialog with rounded corners and showing a title and then a ScrollView with some text. The only thing that is not working to me is the rounded corners. Here I post you my code:
我的 AndroidManifest.xml 帶有我想要的活動以及我的圓角對話框:
my AndroidManifest.xml with the activity I want with my rounded-corners Dialog:
<activity
android:name=".AboutNacimiento"
android:label="@string/about_nac_title"
android:theme="@style/Theme.CustomDialogTheme"
android:screenOrientation="nosensor">
</activity>
然后我的資源具有各自的樣式 (res/layout/values/dialogTheme.xml)
then my resource with respective styles (res/layout/values/dialogTheme.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.CustomDialogTheme"
parent="@android:style/Theme.Dialog">
<item name="android:windowTitleStyle">@style/dialog_title_style</item>
<item name="android:background">@drawable/rounded_dialog</item>
</style>
<style name="dialog_title_style" parent="@android:Widget.TextView">
<item name="android:background">@color/titulo_color</item>
<item name="android:padding">10dip</item>
<item name="android:textSize">20sp</item>
<item name="android:gravity">center</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/texto_blanco</item>
</style>
最后是我想要的圓形對話框的形狀 (res/drawable/rounded_dialog.xml):
and finally the shape I want for my rounded dialog (res/drawable/rounded_dialog.xml) :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/background_color"/>
<stroke android:color="#7F7F7F" android:width="1dp" />
<corners
android:radius="20dp"/>
</shape>
但我得到的唯一圓形"的東西是 TextViews 中的一些邊框......
but the only "rounded" thing I'm getting are some borders in the TextViews...
http://imageshack.us/photo/my-images/515/問題ab.jpg
你能幫我得到我想要的對話框嗎?
could you please help me to get my desired Dialog?
推薦答案
移除默認(rèn)android框架的關(guān)鍵是:
The key thing to remove default android frame is:
MyDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
這是完整的例子:
Dialog MyDialog= new Dialog(MyActivity.this);
MyDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
MyDialog.setContentView(R.layout.my_custom_dialog);
MyDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
MyDialog.show();
這篇關(guān)于無法創(chuàng)建圓角對話框(Android-Eclipse)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!