­

Basic4android(B4A)設置主題樣式

  • 2019 年 11 月 20 日
  • 筆記

一、Android自帶樣式詳解

    android:theme="@android:style/Theme.Dialog" : Activity顯示為對話框模式      android:theme="@android:style/Theme.NoTitleBar" : 不顯示應用程式標題欄      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" : 不顯示應用程式標題欄,並全螢幕      android:theme="Theme.Light ": 背景為白色      android:theme="Theme.Light.NoTitleBar" : 白色背景並無標題欄      android:theme="Theme.Light.NoTitleBar.Fullscreen" : 白色背景,無標題欄,全螢幕      android:theme="Theme.Black" : 背景黑色      android:theme="Theme.Black.NoTitleBar" : 黑色背景並無標題欄      android:theme="Theme.Black.NoTitleBar.Fullscreen" : 黑色背景,無標題欄,全螢幕      android:theme="Theme.Wallpaper" : 用系統桌面為應用程式背景      android:theme="Theme.Wallpaper.NoTitleBar" : 用系統桌面為應用程式背景,且無標題欄      android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" : 用系統桌面為應用程式背景,無標題欄,全螢幕      android:theme="Theme.Translucent : 透明背景      android:theme="Theme.Translucent.NoTitleBar" : 透明背景並無標題      android:theme="Theme.Translucent.NoTitleBar.Fullscreen" : 透明背景並無標題,全螢幕      android:theme="Theme.Panel ": 面板風格顯示      android:theme="Theme.Light.Panel" : 平板風格顯示

二、B4A通過XmlLayoutBuilder類庫修改主題(下期將講通過樣式程式碼實現)

相關程式碼
      #Region  Project Attributes            #ApplicationLabel: B4A_主題設置            #VersionCode: 1            #VersionName:            #SupportedOrientations: unspecified            #CanInstallToExternalStorage: False        #End Region          #Region  Activity Attributes            #FullScreen: False            #IncludeTitle: True        #End Region          Sub Process_Globals            Private Theme_Value As Int        End Sub          Sub Globals            Private res As XmlLayoutBuilder            Private ProgressBar1 As ProgressBar            Private Spinner1 As Spinner        End Sub          Sub Activity_Create(FirstTime As Boolean)            Activity.LoadLayout("main")            ProgressBar1.Progress = 50            Spinner1.AddAll(Array("Item 1", "Item 2", "Item 3"))        End Sub          Sub btnHolo_Click            SetTheme(res.GetResourceId("style", "android:style/Theme.Holo"))        End Sub          Sub btnHoloLight_Click            SetTheme(res.GetResourceId("style", "android:style/Theme.Holo.Light"))        End Sub          Sub btnHoloLightDark_Click            SetTheme(res.GetResourceId("style", "android:style/Theme.Holo.Light.DarkActionBar"))        End Sub          Sub btnOld_Click            SetTheme(16973829)        End Sub          Sub btnMaterialLightDark_Click            SetTheme(res.GetResourceId("style", "android:style/Theme.Material.Light.DarkActionBar"))        End Sub          Sub btnMaterialLight_Click            SetTheme(res.GetResourceId("style", "android:style/Theme.Material.Light"))        End Sub          Sub btnMaterial_Click            SetTheme(res.GetResourceId("style", "android:style/Theme.Material"))        End Sub          Private Sub SetTheme (Theme As Int)            If Theme = 0 Then                ToastMessageShow("Theme not available.", False)                Return            End If            If Theme = Theme_Value Then Return            File.WriteString(File.DirInternal, "theme.txt", Theme)            Theme_Value = Theme            Activity.Finish            StartActivity(Me)        End Sub            #if java        import anywheresoftware.b4a.objects.streams.*;        public void _onCreate() {            try {            if (File.Exists(getFilesDir().toString(), "theme.txt"))                _theme_value = Integer.parseInt(File.ReadString(getFilesDir().toString(), "theme.txt"));            } catch (Exception e) {                throw new RuntimeException(e);            }            if (_theme_value != 0)                setTheme(_theme_value);        }        #end if          Sub Activity_Resume          End Sub          Sub Activity_Pause (UserClosed As Boolean)          End Sub

類庫和實例下載
        https://www.lanzous.com/i7bklih

本期教程到此結束啦!