zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Shell编程常用
    毕设问答
    《如何高效学习》
    《如何阅读一本书》(未完)
    《牧羊少年奇幻之旅》
    2019.04月总结
    上周还是合意的,且找到了一定的遵循4.6-4.12

    错误和异常
    数据结构
  • 原文地址:https://www.cnblogs.com/linzheng/p/1939731.html
Copyright © 2011-2022 走看看