1、Basic4Android 安装使用说明,及学习日记一、安装配置1、安装.net2,安装 jdk2、安装 Android SDK,安装后运行,还会提示要在线下载对应的系统,如选择 Android 4.03如何解决安卓 SDK 无法下载 Package 的问题 -因为网络 IP 被封了。 修改 Hosts 文件C:WindowsSystem32driversetchosts203.208.46.146 203.208.46.146 dl-、打开安卓 SDK 管理器“Android SDK Manager”,点击菜单栏中的“Tools/Options”打开设置窗体。勾选 Force 开头的复选框
2、按钮,然后点击“Close”按钮关闭并保存设置。3、安装.net2 以上( 否则 basic4 一启动报错 000000135)4、运行 Basic4Android 1.9 绿色版 Basic4android.exe二、HelloWorld、问题:运行时编译,可能提示 文件不对,将提示的文件夹复制到 C:Document SettingsAdministrod 目录下;、运行时,应该在 tools 菜单下,启动 MVD?,创建手机模拟器;不过,编译会很慢。建议直接接上手机,系统设置/开发人员选项/ 设置为 USB 调试模式。编译运行速度会加快。、手工创建对象Dim wv As WebView
3、定义wv.Initialize(“wv“) 初始化,关键是指定一个事件名称 后面可以 sub wv_click 之类的事件Activity.AddView(wv,0,0,100%x,100%y) 加入 VIEW,位置可以使用了wv.LoadUrl(“http:/ Timer1 As Timer Timer1.Initialize(“Timer1“,1000)Timer1.Enabled=TrueSub Timer1_Tick /(即interval 事件)Label1.Text=Svr.c End Sub/退出确认Sub Activity_KeyPress (KeyCode As Int) A
4、s Boolean Dim Answ As Int If KeyCode = KeyCodes.KEYCODE_BACK Then Answ = Msgbox2(“确定要退出吗? “, “注意“ , “Yes“, “, “No“, Null) If Answ = DialogResponse.NEGATIVE Then Return True End If End If Return False End Sub /For i = 0 To Cursor1.RowCount -1 Cursor1.Position = iDim img1 As ImageViewimg1.Initialize(“
5、ImgView“)img1.Bitmap = LoadBitmap(File.DirAssets, “audit_template_new.png“)ScrollView1.Panel.AddView(img1, 40dip, img_height, 728dip, 115dip)QuestionRefDim lbl_questionref As Labellbl_questionref.Initialize(“Label“)lbl_questionref.Text = Cursor1.GetString(“QuestionNr“)lbl_questionref.TextColor = Col
6、ors.BlackScrollView1.Panel.AddView(lbl_questionref, 50dip, img_height+10dip, 350dip, 40dip)Question ContentDim lbl_question As Labellbl_question.Initialize(“Label“)lbl_question.Text = Cursor1.GetString(“Question“)lbl_question.TextColor = Colors.DarkGrayScrollView1.Panel.AddView(lbl_question, 50dip,
7、img_height+40dip, 380dip, 70dip) Image Blank Dim img_blank_yes As ImageViewimg_blank_yes.Initialize(“YES“)img_blank_yes.Bitmap = LoadBitmap(File.DirAssets, “yes_blank.png“)img_blank_yes.BringToFrontimg_blank_yes.Tag = iScrollView1.Panel.AddView(img_blank_yes, 475dip, img_height+31dip, 47dip, 50dip)A
8、dd 115 to add to the TOP valueimg_height = img_height + 115dip Next/ScrollView1.Panel.Height = 800dip btn1.Initialize(“)btn1.Text = “True“btn2.Initialize(“)btn2.Text = “False“label1.Initialize(“)label1.Text = “True“label1.Color = Colors.Cyanlabel2.Initialize(“)label2.Text = “label2.Color = Colors.Ye
9、llowspin1.Initialize(“) ScrollView1.Panel.AddView(spin1, 10dip, 5dip, 200dip, 50dip)ScrollView1.Panel.AddView(btn1, 10dip, 55dip, 200dip, 50dip)ScrollView1.Panel.AddView(btn2, 10dip, 105dip, 200dip, 50dip)ScrollView1.Panel.AddView(label1, 10dip,155dip, 200dip, 50dip)ScrollView1.Panel.AddView(label2,
10、 10dip,205dip, 200dip, 50dip)spin1.AddAll(Array As String(“a“, “b“, “c“, “d“) btn1.Visible = False btn2.Visible = False/1、另外,使用 B4A Bridge,调试很方便、手机上下载安装 B4A Bridge,并启动、Basic4Android 1.9,菜单 Desiger,打开界面可视化设计器,类似于 Form,可将文件保存为 Form1,Form2 等。Timer 是不可视组件设计器中创建的不需要屏幕方向:Phone library.It can also be done
11、by code with SetScreenOrientation from the Phone library: Landscape Phone1.SetScreenOrientation(0) Portrait Phone1.SetScreenOrientation(1) Both Phone1.SetScreenOrientation(-1) 启动另一程序:Phone library.The PackageManager is an object in the Phone library. The exact package name is needed ! Dim pm As Pack
12、ageManager Dim in As Intent in.Initialize(“, “) in = pm.GetApplicationIntent If in.IsInitialized Then StartActivity(in) End If判断屏幕方向:The code below detects the screen orientaion, comparing if the activity width is greater than the activity height then the orientation is “landscape“ otherwise its “po
13、rtrait“. Sub Globals Dim Orientation As String End Sub Sub Activity_Create(FirstTime As Boolean) If Activity.Width Activity.Height Then Orientation = “Landscape“ Else Orientation = “Portait“ End If End Sub启动内部计算器:Sub Calculator Dim i As Intent i.Initialize(“, “) i.SetComponent(“com.android.calculator2/.Calculator“) Try StartActivity(i) Catch ToastMessageShow(“Calculator app not found.“, True) End Try End Sub