Basic4android(B4A)设置主题样式

  • 2019 年 11 月 20 日
  • 筆記

一、安卓自带样式详解

    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

本期教程到此结束啦!