• android组件通讯 IntentCategory属性


    程序文件

    /Chapter06_Intent_Category/src/com/amaker/test/MainActivity.java

    代码
    package com.amaker.test;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;

    /**
    * 测试Intent 的 Category属性
    */
    public class MainActivity extends Activity
    {
    // 声明 Button
    private Button b1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 设置当前布局
    setContentView(R.layout.main);
    // 实例化 Button
    b1 = (Button)findViewById(R.id.Button01);
    // 为Button 添加监听器
    b1.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    // 实例化Intent
    Intent i = new Intent();
    // 添加Action属性
    i.setAction(Intent.ACTION_MAIN);
    // 添加Category属性
    i.addCategory(Intent.CATEGORY_HOME);
    // 启动Activity
    startActivity(i);
    }
    });
    }
    }

    布局文件

    /Chapter06_Intent_Category/res/layout/main.xml

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

    <TextView
    android:layout_width="fill_parent"
    android:layout_height
    ="wrap_content"
    android:text
    ="Intent Category 测试" />

    <Button
    android:id="@+id/Button01"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:text
    ="回到Home"></Button>


    </LinearLayout>
  • 相关阅读:
    ObjectDataSource用法之六(刪除)
    ObjectDataSourc用法之七(新增)
    C# 装箱和拆箱
    Android SD卡中压缩包解压(ZIP文件)
    Android 调用系统的拨号服务实现 电话拨打功能
    Android 判断SD卡存不存在
    android中IdleHandler的使用
    android使用遥控器模拟鼠标拖拽操作
    Android SD卡 文件或目录拷贝、复制、粘贴
    C#在线获取歌词(转)
  • 原文地址:https://www.cnblogs.com/linzheng/p/1939731.html
Copyright © 2020-2023  润新知