首页 文章 精选 留言 我的

精选列表

搜索[组件库],共10000篇文章
优秀的个人博客,低调大师

android组件通讯 Intent-Action属性

Action属性应用实例 1、自定义Action属性 程序文件 /Chapter06_Intent_TestAction/src/com/amaker/ch06/app/MainActivity.java 代码 packagecom.amaker.ch06.app; importandroid.app.Activity; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; /** * *测试IntentAction属性 */ publicclassMainActivityextendsActivity{ //定义Action属性常量 publicstaticfinalStringMY_ACTION="com.amaker.ch07.app.MY_ACTION"; //声明Button privateButtonbtn; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //设置布局视图 setContentView(R.layout.main); //实例化Button btn=(Button)findViewById(R.id.Button01); btn.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ //实例化Intent Intentintent=newIntent(); //为Intent设置Action属性 intent.setAction(MY_ACTION); //启动Activity startActivity(intent); } }); } } /Chapter06_Intent_TestAction/src/com/amaker/ch06/app/MyActivity.java 代码 packagecom.amaker.ch06.app; importandroid.app.Activity; importandroid.content.Intent; importandroid.os.Bundle; importandroid.widget.TextView; /** *测试IntentAction属性 */ publicclassMyActivityextendsActivity{ //声明TextView privateTextViewtv; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //设置视图布局 setContentView(R.layout.my_layout); //获得Intent对象 Intentintent=getIntent(); //获得Action Stringaction=intent.getAction(); //获得TextView tv=(TextView)findViewById(R.id.TextView01); //设置内容 tv.setText(action); } } 布局文件 /Chapter06_Intent_TestAction/res/layout/main.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:text="测试Intent的Action属性" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout> /Chapter06_Intent_TestAction/res/layout/my_layout.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="@+id/TextView01" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </LinearLayout> 清单文件 /Chapter06_Intent_TestAction/AndroidManifest.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.amaker.ch06.app" android:versionCode="1" android:versionName="1.0"> <applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> <activityandroid:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activityandroid:name="MyActivity"> <intent-filter> <actionandroid:name="com.amaker.ch06.app.MY_ACTION"/> <categoryandroid:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application> <uses-sdkandroid:minSdkVersion="3"/> </manifest> 2、访问系统的Action属性 程序文件 /Chapter06_Intent_TestAction2/src/com/amaker/ch06/app/MainActivity.java 代码 packagecom.amaker.ch06.app; importandroid.app.Activity; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; /** * *测试IntentAction属性 */ publicclassMainActivityextendsActivity{ //声明Button privateButtonbtn; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //设置当前布局视图 setContentView(R.layout.main); //实例化Button btn=(Button)findViewById(R.id.Button01); btn.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ //创建Intent Intentintent=newIntent(); //设置IntentAction属性 intent.setAction(Intent.ACTION_GET_CONTENT); //设置IntentType属性 intent.setType("vnd.android.cursor.item/phone"); //启动Activity startActivity(intent); } }); } } 布局文件 /Chapter06_Intent_TestAction2/res/layout/main.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:text="测试Intent的Action属性" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout> 清单文件 /Chapter06_Intent_TestAction2/AndroidManifest.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.amaker.ch06.app" android:versionCode="1" android:versionName="1.0"> <applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> <activityandroid:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> <uses-sdkandroid:minSdkVersion="3"/> </manifest> 本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080670

优秀的个人博客,低调大师

android组件通讯 Intent-Category属性

程序文件 /Chapter06_Intent_Category/src/com/amaker/test/MainActivity.java 代码 packagecom.amaker.test; importandroid.app.Activity; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; /** *测试Intent的Category属性 */ publicclassMainActivityextendsActivity{ //声明Button privateButtonb1; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //设置当前布局 setContentView(R.layout.main); //实例化Button b1=(Button)findViewById(R.id.Button01); //为Button添加监听器 b1.setOnClickListener(newOnClickListener(){ @Override publicvoidonClick(Viewv){ //实例化Intent Intenti=newIntent(); //添加Action属性 i.setAction(Intent.ACTION_MAIN); //添加Category属性 i.addCategory(Intent.CATEGORY_HOME); //启动Activity startActivity(i); } }); } } 布局文件 /Chapter06_Intent_Category/res/layout/main.xml 代码 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns: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="IntentCategory测试"/> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="回到Home"></Button> </LinearLayout> 本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1080666

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册