2012-01-05 2 views
1

대화 상자의 xml 안에있는 버튼으로 사용자 정의 대화 상자를 닫거나 대화 상자의 아무 곳이나 눌러 닫는 방법을 찾고 있습니다. 내가 가진 것은 이것이다. 내용이있는 사용자 정의 대화 상자를 가져 오는 Image Button이있는 레이아웃. 나는 setCanceledOnTouchOutside (true)를 가지고있다; 그게 작동하지만, 대화 상자가 화면의 대부분을 채울 필요가 있으며 사용자가 사용 가능한 작은 공간을 클릭하기가 어려울 수 있습니다. 그러면 어떻게해야합니까? 레이아웃 안의 Android 닫기 사용자 정의 대화 상자

내 자바 코드 :

import android.app.Activity; 
import android.app.Dialog; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ImageButton; 

public class Rose extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     this.setRequestedOrientation(
     ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     setContentView(R.layout.rose); 

     ImageButton b = (ImageButton) findViewById(R.id.imageButton1); 
     b.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       Dialog d1 = new Dialog(Rose.this); 
       d1.setContentView(R.layout.tariquet); 
       d1.setCanceledOnTouchOutside(true); 
       d1.show(); 


      } 
     }); 
    } 

} 

그리고 내 XML :라고

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fitsSystemWindows="true" 
    android:isScrollContainer="true" 
    android:minHeight="1100dp" 
    android:minWidth="650dp"> 
    <ImageView 
    android:src="@drawable/rose_tariquet" 
    android:id="@+id/imageView1" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"></ImageView> 
    <Button android:text="X" 
    android:layout_height="wrap_content" 
    android:id="@+id/button1" 
    android:layout_width="55dp" 
    android:layout_gravity="right"></Button> 

</FrameLayout> 

답변

0
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(); 
} 
} 

:

CustomizeDialog customizeDialog = new CustomizeDialog(CustomDialog.this,"clickme"); 
customizeDialog.show(); 
+0

난 그 확실하지, 작업을 얻이 수없는 것 내가 뭘 잘못하고있어. 위 코드를 사용하고 ID를 대체하여 CustomizeDialog라는 새로운 Java 파일을 만들었습니다. – condensation

+0

편집 해 주시겠습니까? – pengwang

+0

어디에 넣어야합니까? 코드 끝 부분에 구문 오류를 넣으면 여러 가지 오류가 발생합니다. – condensation

관련 문제