#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