2013-04-25 54 views

回答

2

歡迎來到Stackoverflow。

它不是對話框。其活動作爲一個對話框

enter image description here

public class diaActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.test_dialog); 
    } 
} 

test_dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="42dp" 
     android:orientation="horizontal" 
     android:weightSum="3" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="Cancle" /> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="OK" /> 
    </LinearLayout> 

    <EditText 
     android:id="@+id/editText1" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:ems="10" 
     android:inputType="textPostalAddress" > 

     <requestFocus /> 
    </EditText> 

</LinearLayout> 

在Android清單文件中添加您的活動主題:

<activity 
      android:name="diaActivity" 
      android:theme="@android:style/Theme.Holo.Dialog" > 
     </activity> 

爲< 11 API,您有使用

<activity 
      android:name="diaActivity" 
      android:theme="@android:style/Theme.Dialog" > 
     </activity> 

編輯:

關閉鍵盤和退出使用此代碼:

public void onBackPressed() { 

InputMethodManager imm = (InputMethodManager)getSystemService(
     Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); 

finish(); 

} 
+0

感謝您的回答,但我需要鍵盤一起關閉EditText。 – user1931699 2013-04-25 07:33:05

+0

@ user1931699:查看我編輯的答案.. – 2013-04-25 08:37:46