前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Basic4android(B4A)设置主题样式

Basic4android(B4A)设置主题样式

作者头像
一线编程
发布2019-11-20 10:18:15
1.3K0
发布2019-11-20 10:18:15
举报
文章被收录于专栏:办公魔盒办公魔盒
一、安卓自带样式详解
代码语言:javascript
复制
    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类库修改主题(下期将讲通过样式代码实现)
相关代码
代码语言:javascript
复制
      #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

类库和实例下载
代码语言:javascript
复制
        https://www.lanzous.com/i7bklih
本期教程到此结束啦!
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-11-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 办公魔盒 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、安卓自带样式详解
  • 二、B4A通过XmlLayoutBuilder类库修改主题(下期将讲通过样式代码实现)
    • 相关代码
      • 类库和实例下载
      • 本期教程到此结束啦!
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档