歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發:AlertDialog自定義樣式

Android開發:AlertDialog自定義樣式

日期:2017/3/1 11:17:02   编辑:Linux編程

像列表這種選擇項的彈出式對話框,要改變樣式一般都采取重寫layout方式

今天才了解到 其實可以自定義樣式,與大家分享下,其實很簡單

  1. AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));

然後自定義自己的樣式就可以了

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <style name="AlertDialogCustom" parent="@Android:style/AlertDialog">
  4. <item name="android:textColor">#00FF00</item>
  5. <item name="android:typeface">monospace</item>
  6. <item name="android:textSize">10sp</item>
  7. </style>
  8. </resources>
Copyright © Linux教程網 All Rights Reserved