2011-09-21 43 views
5

i tùy chỉnh một hộp thoại:làm thế nào để loại bỏ khung hình chữ nhật của hộp thoại tùy chỉnh

public class CustomizeDialog extends Dialog implements OnClickListener { 
Button close; 
TextView tv; 
public CustomizeDialog(Context context,String Stringcontent) { 
    super(context); 
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    setContentView(R.layout.custom_diolog_main); 
    tv=(TextView) findViewById(R.id.content); 
    tv.setText(Stringcontent); 
    close = (Button) findViewById(R.id.close); 
    close.setOnClickListener(this); 
} 

@Override 
public void onClick(View v) {  
    if (v == close) 
     dismiss(); 
} 

} 

xml là

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="100dip" 
android:orientation="vertical" 
android:background="@drawable/custom_diolog_bg" 
android:layout_width="250dip"> 
<TextView android:layout_height="wrap_content" 
    android:textColor="#000" 
    android:textStyle="bold" 
    android:textSize="18sp" 
    android:id="@+id/content" 
    android:layout_marginLeft="15dip" 
    android:layout_marginTop="5dip" 
    android:layout_alignParentTop="true" 
    android:layout_width="250dip" 
    android:text=" Custom Dialog "/> 


<Button android:layout_width="70dip" 
    android:layout_marginLeft="80dip" 
    android:background="@drawable/custom_dialog_button_bg" 
    android:layout_alignParentBottom="true" 
    android:layout_height="40dip" android:text="关闭" 
     android:id="@+id/close"></Button> 
</RelativeLayout> 

thoại của tôi là vrry tốt, nhưng custom_diolog_bg là một hình ảnh hình chữ nhật tròn, và khi tôi hiển thị hộp thoại của tôi, nó cho thấy một khung hệ thống cư xử tùy chỉnh của tôi, vì vậy tôi đã sử dụng this.getwindow.setBackgroundDrawable (null), sau đó hệ thống Frame có vẻ đã loại bỏ nhưng chỉ có bốn góc không loại bỏ, chúng tôi cũng thấy tối bốn góc, bởi vì tôi đã sử dụng hình ảnh hình chữ nhật được làm tròn.so câu hỏi của tôi về cách xóa tất cả Khung hình sao cho hộp thoại có vẻ rất tốt

hình ảnh là http://i.stack.imgur.com/EG7oz.jpg, vì vậy bạn có thể thấy có khung tối ở cuối cùng, cách xóa nó? cảm ơn bạn

Trả lời

1

thay vì gọi

super(context); 

gọi

super(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 

Cập nhật: Sử dụng layout xml này thay vì

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="100dip" 
    android:orientation="vertical" 
    android:background="@drawable/custom_diolog_bg" 
    android:layout_width="250dip"> 
    <LinearLayout 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:orientation="vertical" 
     android:layout_centerInParent="true"> 
     <TextView 
     android:layout_height="wrap_content" 
     android:textColor="#000" 
     android:textStyle="bold" 
     android:textSize="18sp" 
     android:id="@+id/content" 
     android:layout_marginLeft="15dip" 
     android:layout_marginTop="5dip" 
     android:layout_alignParentTop="true" 
     android:layout_width="250dip" 
     android:text=" Custom Dialog " /> 
    <Button 
     android:layout_width="70dip" 
     android:layout_marginLeft="80dip" 
     android:background="@drawable/custom_dialog_button_bg" 
     android:layout_alignParentBottom="true" 
     android:layout_height="40dip" 
     android:text="关闭" 
     android:id="@+id/close"></Button> 
    </LinearLayout> 
</RelativeLayout> 
+0

nếu tôi sử dụng tính năng này, vị trí hiển thị hộp thoại letf -Up không ở giữa màn hình. – pengwang

+0

Tôi đã cập nhật câu trả lời của mình có một cái nhìn tại đó – ingsaurabh

+0

tôi đã sử dụng điều này, nhưng nó không thể hữu ích, cảm ơn bạn đã trả lời – pengwang

2

Dialog mydialog = new thoại (this, android. R.style.Theme_Translucent_NoTitleBar);

+1

nếu tôi sử dụng điều này, vị trí hiển thị hộp thoại letf -Up không ở giữa màn hình. – pengwang

19

Giải pháp mà làm việc cho tôi

<style name="DialogTheme" parent="@android:style/Theme.Dialog"> 
     <item name="android:windowBackground">@android:color/transparent</item>   
</style> 

Dialog dialog = new Dialog(this, R.style.DialogTheme); 
1

Hãy thử điều này nó làm việc cho tôi như một say mê.

ContextThemeWrapper wrapper = new ContextThemeWrapper(this, android.R.style.Theme_Holo); 
final LayoutInflater inflater = (LayoutInflater) wrapper.getSystemService(LAYOUT_INFLATER_SERVICE); 
AlertDialog.Builder builder = new AlertDialog.Builder(wrapper); 
+0

Dude! cảm ơn, điều đó rất thông minh. –

+0

Cảm ơn .... Thật tốt khi biết rằng điều đó đã giúp ích! – Nova

4

Sử dụng sau dòng trước khi gọi setContentView(): -

getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
getWindow().setBackgroundDrawable(
      new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

sẽ làm việc một cách hoàn hảo.

+0

câu trả lời hay, làm việc .. –

Các vấn đề liên quan