2017-01-08 6 views
2

나는 alertdialog에서 내용을 감싸는 방법을 묻고 싶습니다. 대화 상자의 현재 출력에 흰색 필드가 너무 깁니다.안드로이드에서 alertdialog를 감싸는 방법?

누군가이 문제를 이해하는 데 도움이되기를 바랍니다. 감사합니다.

다음
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:minWidth="10dp" 
    android:minHeight="10dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    tools:context="com.bloxofcode.toggle.MainActivity"> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="50sp" 
      android:background="@color/colorHeaderDialog" 
      android:textColor="@android:color/white" 
      android:text="@string/select_gender" 
      android:padding="15dp" 
      android:gravity="center_horizontal|left"/> 

     <EditText 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="30sp" 
      android:padding="15dp" 
      android:text="Sample" 
      android:id="@+id/editText" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <ToggleButton 
       android:text="ToggleButton" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/toggleButtonMale" 
       android:textOn="" 
       android:textOff="" 
       android:focusable="false" 
       android:background="@drawable/check_male" 
       android:layout_weight="1" /> 

      <ToggleButton 
       android:text="ToggleButton" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/toggleButtonFemale" 
       android:textOn="" 
       android:textOff="" 
       android:focusable="false" 
       android:background="@drawable/check_male" 
       android:layout_weight="1" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:padding="10dp"> 
      <Button 
       android:id="@+id/btnCancel" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Cancel" 
       android:textSize="20dp" 
       android:padding="30dp" 
       android:textColor="@android:color/white" 
       android:layout_weight="1"/> 
      <Button 
       android:id="@+id/btnAccept" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Accept" 
       android:textSize="20dp" 
       android:padding="30dp" 
       android:background="@color/colorDialogOK" 
       android:textColor="@android:color/white" 
       android:layout_weight="1"/> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 

는 MainActivity.java 내 구현의 일부입니다 :

AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); 
View mView = getLayoutInflater().inflate(R.layout.activity_dialog, null); 
..... 
mBuilder.setView(mView); 
final AlertDialog dialog = mBuilder.create(); 
dialog.show(); 
+0

일 [여기에 자세한 답변과 정확히 경고 대화 상자에서 어떤 일이 일어나고] http://stackoverflow.com/a/14918253/7368826 () –

답변

1

이 같은 대화 상자를 만들어보십시오

enter image description here

여기 내 activity_dialog.xml입니다. 이 완벽하게 작동하고 즉시 대화 로직은

public class CustomDialog extends Dialog implements 
     android.view.View.OnClickListener { 

    public Activity c; 
    public CustomDialog d; 
    public Button yes, no; 

    public CustomDialog(Activity a) { 
     super(a); 
     // TODO Auto-generated constructor stub 
     this.c = a; 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.dialog_layout); 
     Button button = (Button) findViewById(R.id.button); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       //dosomething 
      } 
     }); 
    } 
} 
+0

안녕하십니까, 빠른 응답을 주셔서 감사합니다.하지만 이미 처음에 그렇게했습니다. match_parent를 사용할 때의 문제점은 이미지와 너무 많은 안쪽 여백을 늘리는 것입니다. – iamcoder

+0

오케 나는 밖으로 몇 가지 시도하고 이것은 나를 위해 큰 작품, 내 대답을 편집 –

+0

안녕하세요 선생님, 감사를 위해 다시 감사합니다,하지만 어떻게 이것을 구현할 수 있습니까? 초보자 인 것에 대해 유감스럽게 여기에서. – iamcoder

0

은 정제 및 큰 장치에서보기를 방해 하듯이 대화의 내용을 래핑하는 정확하지 않은 희망 활동 로직 당신에게서 구분된다.

어쨌든 귀하의 요구 사항에 내놓고 .. 희망이 링크 AlertDialog with custom view: Resize to wrap the view's content

+0

안녕하세요. 이미 해당 기사를 읽었습니다 ... 실행 해 보셨습니까? – iamcoder

+0

네, 작동하는 것 같습니다. 한 번 해보고 어떤 문제에 직면했는지 알려주시겠습니까? – ChaitanyaAtkuri

+0

안녕하세요. 위의 코드는 내 코드에서 깔끔하고 단순하게 처리 할 것입니다. 이지만이 다른 방법으로 참조를 시도합니다. 다시 한 번 감사드립니다. – iamcoder