本文将讲述一个鷹文恐惧症患者如何【使用ruboto_irb调用android_api】的 嗯对~乃需要准备的有:
一部安卓爪机 # 在下使用的版本是4.0.4
ruboto-irb # 请到软件商店中自找 Android API Browser # 同上 这是一个手册一样的东西 连数据包一起要9mb的样子 随便你们装不装吧 这里介绍两种调用方式(请注意ruboto中不能出现中文):
1. Import 【示例全部来自预置脚本
#弹出拨电话界面并设置电话号码为123
import "android.content.Intent"
import "android.net.Uri"
intent = Intent.new(Intent::ACTION_VIEW)
intent.setData(Uri.parse("tel:123"))
$irb.startActivity(intent)
#提示框
import 'android.widget.Toast'
Toast.makeText($irb, "Hello Ruboto!", Toast::LENGTH_LONG).show
也许你们能从中看出什么,但是接下来就是主要内容了!【喂上面的跳过了吗
2. Require
craps.rb (by Daniel Jackoway) # 这一基本示例包含了:TextView(显示文字), :LinearLayout(线性布局控件), :Button(按钮), :ListView(显示列表), :EditText(编辑框)
require 'ruboto/activity'
require 'ruboto/widget'
require 'ruboto/util/toast'
ruboto_import_widgets :TextView, :LinearLayout, :Button, :ListView, :EditText # 是一个类似import的方法,语法和attr什么的一样,需要什么控件就加什么
# 以下是基本结构
[code]class A
def on_create(bundle) # 这个方法名是必须的 实际脚本执行时调用这个方法绘制主界面
super
setTitle "Somewords"
set_content_view(
linear_layout(:orientation => :vertical){
linear_layout(:orientation => :horizontal){
text_view :text => "foo";text_view :text => "bar"
button :text => "buzz", :width => :wrap_content, :on_click_listener => (proc{do something})
}
}
)
end
def change_activity(str)
start_ruboto_activity :class_name => str
end
end[/code]
如果有哪里写得不够请尽管@在下~~【私信也可