Android自定義Dialog 軟鍵盤、大小的設置

Dialog中EditText可彈出軟鍵盤

<style name="CustomDialogStyle" parent="@android:style/Theme.Dialog">
  <item name="android:windowFrame">@null</item>
  <item name="android:windowIsFloating">true</item>
  <item name="android:windowIsTranslucent">true</item>
  <item name="android:windowNoTitle">true</item>
  <item name="android:background">@android:color/transparent</item>
  <item name="android:windowBackground">@android:color/transparent</item>
  <item name="android:backgroundDimEnabled">true</item>
  <item name="android:backgroundDimAmount">0.6</item>
</style>

把style設置到dialog中
Dialog ad = new Dialog(context,R.style.CustomDialogStyle);
ad.show();
Window window = ad.getWindow();
window.setBackgroundDrawable(new ColorDrawable(0));  
window.setContentView(R.layout.cancel_sos_dialog);

Dialog中設置大小

代碼承接上面的代碼
WindowManager.LayoutParams  lp= window.getAttributes();  
lp.width=screenWidth - 50;//定義寬度  
lp.height=LayoutParams.WRAP_CONTENT;//定義高度  
window.setAttributes(lp);






發佈了25 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章