隐式Intent跳转
来源:互联网 发布:怎么运营好淘宝店铺 编辑:程序博客网 时间:2024/04/28 03:26
在Intent中明确表明跳转界面的为显式跳转,还有另一种跳转为隐式跳转,即为不明确表明跳转界面。
首先,在Activity中建立几个Button,分别实现拨打电话,发送短信,打开网页,播放音乐,视频,打开图片,安装APK,添加通知栏。在实现上述功能后,点击Activity中的图片,弹出PopWindow,PopWindow中有相册,相机,退出按钮,点击相册更经过裁剪后换图片,点击相机经过裁剪后更换,点击退出返回Activity界面
1、在清单文件中添加用户权限,
<uses-permission android:name="android.permission.CALL_PHONE" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />在Activity中使用的是布局监听,
public class IntentActivity extends AppCompatActivity implements View.OnClickListener{ private View view; private RoundImageView riv; //圆形图片 private PopupWindow pw; //全局PopWindow
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intent); pw = new PopupWindow(view); Button bt1= (Button) findViewById(R.id.bt1); //找到Button Button bt2= (Button) findViewById(R.id.bt2); Button bt3= (Button) findViewById(R.id.bt3); Button bt4= (Button) findViewById(R.id.bt4); Button bt5= (Button) findViewById(R.id.bt5); Button bt6= (Button) findViewById(R.id.bt6); Button bt7= (Button) findViewById(R.id.bt7); Button bt8= (Button) findViewById(R.id.bt8); riv= (RoundImageView) findViewById(R.id.riv); view=getLayoutInflater().inflate(R.layout.pop_layout, null); //得到PopWindow布局 Button img= (Button) view.findViewById(R.id.img); Button cream= (Button) view.findViewById(R.id.cream); Button exit= (Button) view.findViewById(R.id.exit); bt1.setOnClickListener(this); //设置监听事件 bt2.setOnClickListener(this); bt3.setOnClickListener(this); bt4.setOnClickListener(this); bt5.setOnClickListener(this); bt6.setOnClickListener(this); bt7.setOnClickListener(this); bt8.setOnClickListener(this); img.setOnClickListener(this); cream.setOnClickListener(this); exit.setOnClickListener(this); riv.setOnClickListener(this); }
}
布局代码如下
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" //布局中被注释掉的部分为测试PopWindow使用 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.example.administrator.intent.IntentActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/bt1" android:text="拨打电话" android:layout_alignParentTop="true" android:layout_alignParentStart="true" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/bt2" android:text="短信" android:layout_below="@+id/bt1" android:layout_alignParentStart="true" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/bt3" android:text="网页" android:layout_below="@+id/bt2" android:layout_alignParentEnd="true" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/bt4" android:text="播放音乐" android:layout_below="@+id/bt3" android:layout_alignParentStart="true" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/bt5" android:text="视频" android:layout_below="@+id/bt4" android:layout_alignParentEnd="true" /> <!--<Button--> <!--android:layout_width="match_parent"--> <!--android:layout_height="wrap_content"--> <!--android:text="图片"--> <!--android:id="@+id/bt6"--> <!--android:layout_below="@+id/bt5"--> <!--android:layout_alignParentEnd="true"--> <!--android:layout_marginTop="43dp" />--> <!--<Button--> <!--android:layout_width="match_parent"--> <!--android:layout_height="wrap_content"--> <!--android:text="安装APK"--> <!--android:id="@+id/bt7"--> <!--android:layout_alignParentEnd="true"--> <!--android:layout_below="@+id/bt6" />--> <!--<Button--> <!--android:layout_width="match_parent"--> <!--android:layout_height="wrap_content"--> <!--android:id="@+id/bt8"--> <!--android:text="通知拦"--> <!--android:layout_below="@+id/bt7"--> <!--android:layout_alignParentStart="true" />--> <com.example.administrator.intent.RoundImageView android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/riv" android:src="@mipmap/image3" android:layout_below="@+id/bt5" android:layout_alignParentStart="true" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" android:layout_alignTop="@+id/riv" android:layout_toEndOf="@+id/riv" android:layout_marginStart="40dp" /></RelativeLayout>
@Override public void onClick(View v) { int id= v.getId(); switch(id){ case R.id.bt1: Uri uri=Uri.parse("tel:10086"); Intent intent =new Intent(Intent.ACTION_DIAL,uri); startActivity(intent); break; case R.id.bt2: Intent it2=new Intent(Intent.ACTION_VIEW); it2.putExtra("sms_body","你好"); it2.setType("vnd.android-dir/mms-sms"); startActivity(it2); break; case R.id.bt3: Uri uri1=Uri.parse("http://www.baidu.com"); Intent it3=new Intent(Intent.ACTION_VIEW,uri1); startActivity(it3); break; case R.id.bt4: Intent it4 =new Intent(Intent.ACTION_VIEW); File file =new File(""); it4.setDataAndType(Uri.fromFile(file), "audio/*"); startActivity(it4); break; case R.id.bt5: Intent it5 =new Intent(Intent.ACTION_VIEW); File file1=new File(""); it5.setDataAndType(Uri.fromFile(file1),"video/*"); startActivity(it5); break;// case R.id.bt6:// Intent it6 =new Intent(Intent.ACTION_VIEW);// File file2=new File("");// it6.setDataAndType(Uri.fromFile(file2),"image/*");// startActivity(it6);// break;//// case R.id.bt7:// Intent it7=new Intent(Intent.ACTION_VIEW);// it7.setDataAndType(Uri.parse("file:///sdcard/qq.apk"),// "application/vnd.android.package-archive");// startActivity(it7);// break;// case R.id.bt8:// notification();// break; case R.id.riv: pw.setFocusable(true); //设置点击页面其他位置可退出 pw.setAnimationStyle(R.style.popStyle); //在drawable中建立anim文件夹,存放动画进入,退出效果 backgroundAlpha(0.3f); // ColorDrawable cd = new ColorDrawable(); pw.setBackgroundDrawable(cd); Log.d("===", "111111"); int width=getResources().getDisplayMetrics().widthPixels; pw.setWidth(width); int height = getResources().getDisplayMetrics().heightPixels/4; pw.setHeight(height); pw.showAtLocation(findViewById(R.id.bt1), Gravity.BOTTOM | Gravity.CENTER, 0, 0); pw.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { backgroundAlpha(1.0f); } }); break; case R.id.exit: Log.d("===", "asddd"); pw.dismiss(); break; case R.id.img: photoPhoto(); break; case R.id.cream: tekePhoto(); break; } }
0 0
- 隐式Intent跳转
- 隐式Intent实现Activity跳转
- Intent跳转
- Intent跳转
- Intent跳转
- intent跳转
- intent跳转
- Intent 跳转
- Intent跳转
- Intent跳转
- 跳转,Intent跳转页面
- Android - Intent - 界面跳转
- Android - Intent - 界面跳转
- Intent 介绍--窗体跳转
- Intent 各种跳转
- Intent 各种跳转
- android intent 跳转
- Intent 跳转Activity
- 设计模式总结之Proxy Pattern(代理模式)
- Android手机——读取手机电话+短信+网页+图片+音乐+视频+APK+通知栏消息+换头像
- EventBus使用及简析
- iOS开发-警告收录及科学快速的消除方法
- TOMCAT-SSL双向认证-配置实例
- 隐式Intent跳转
- String, StringBuffer, StringBuilder
- java 判断邮箱和手机
- POJ 1988 Cube Stacking(带权并查集)
- Android版本检测更新
- pb的find函数
- gulp自动化构建工具之src, dist通配符*,**
- 深入 char * ,char ** ,char a[ ] ,char *a[] 内核
- @IsMqFunction(paramNames={"categoryId","categoryName"})