codecamp

Android Activity

Activity显示应用程序的用户界面,其可以包含诸如按钮,标签,文本框等小部件。

通常,你使用XML文件定义UI,例如位于项目的 res/layout 文件夹中的main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

      <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="hello" />

</LinearLayout>

在运行时,使用Activity类的setContentView()方法,在Activity类的onCreate()方法
处理程序中加载XML UI:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

在编译期间,XML文件中的每个元素都将被编译为其等效的Android GUI类,其中的属性由方法表示。

然后,Android系统在加载Activity时创建Activity的UI。

上面的代码生成以下结果。

Android Activity



Android 解析JSON数据
Android Activity生命周期
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }