Androi UI Intent

Intent理论介绍: http://www.cnblogs.com/skynet/archive/2010/07/20/1781644.html


自定义Action

1. 建一个HelloWord 类似的project (名为 ActionTest)

修改ActionTestManifest.xml 为:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.ActionTest"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ActionTestActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="test_action" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

</manifest>

2. 建一个可以相应一个button的project, 把其中到按键相应函数修改为:

        mButton1 = (Button) findViewById(R.id.Button1);
        mButton1.setText("Button");
        //mButton1.setWidth(100);
        //mButton1.setHeight(50);
        mButton1.setTextColor(Clolor.GREEN);
        
        mButton1.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v){
                Toast toast = Toast.makeText(IDOdestopActivity.this,"you press button  " +
                         mButton1.getText() ,Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP, 0, 100);
               toast.show();
                Intent In = new Intent();
                In.setAction("test_action");
                startActivity(In);
            }
        });

这样后点击button就会跑程序ActionTest。


应用2 : 打开PDF文件

    private void OpenGuidPdf()
    {
          Intent intent = new Intent("android.intent.action.VIEW");
          intent.addCategory("android.intent.category.DEFAULT");
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          Uri uri = Uri.fromFile(new File("/data/uifinajuly20.pdf"));
          intent.setDataAndType(uri, "application/pdf");
          startActivity(intent);
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值