AndroidStudio--Intent(意图)_android studio隐式意图

tools:context=".MainActivity">

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="409dp"
    android:layout_height="270dp"
    android:orientation="vertical"
    tools:layout_editor_absoluteX="198dp"
    tools:layout_editor_absoluteY="47dp">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap\_content"
        android:layout_height="wrap\_content"
        android:text="三种方式"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.13" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap\_content"
        android:layout_height="wrap\_content"
        android:text="方式一"
        tools:layout_editor_absoluteX="161dp"
        tools:layout_editor_absoluteY="184dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap\_content"
        android:layout_height="wrap\_content"
        android:text="方式二"
        tools:layout_editor_absoluteX="164dp"
        tools:layout_editor_absoluteY="281dp" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap\_content"
        android:layout_height="wrap\_content"
        android:text="方式三"
        tools:layout_editor_absoluteX="161dp"
        tools:layout_editor_absoluteY="372dp" />

</LinearLayout>

</android.support.constraint.motion.MotionLayout>


activity\_date.xml



<?xml version="1.0" encoding="utf-8"?>

<DatePicker
    android:layout_width="wrap\_content"
    android:layout_height="wrap\_content"
    android:layout_x="5dp"
    android:layout_y="2dp"></DatePicker>

activity\_clock.xml



<?xml version="1.0" encoding="utf-8"?>

<TimePicker
    android:layout_width="match\_parent"
    android:layout_height="match\_parent"></TimePicker>

三种显示intent的方式



public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Button type1_btn;
Button type2_btn;
Button type3_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    type1_btn = (Button) findViewById(R.id.button);
    type2_btn = (Button) findViewById(R.id.button2);
    type3_btn = (Button) findViewById(R.id.button3);
    type1_btn.setOnClickListener(this);
    type2_btn.setOnClickListener(this);
    type3_btn.setOnClickListener(this);
}
@Override
public void onClick(View v){
    Intent intent=new Intent();
    switch (v.getId()){
            //
        case R.id.button:
            intent.setClass(this,ClockActivity.class);
            break;
            //
        case R.id.button2:
            intent.setClassName(this,"com.example.buttondemo.DateActivity");
            break;
            //打开其他APP的Activity
        case R.id.button3:
            intent.setClassName("com.example.helloworld","com.example.helloworld.MainActivity");
            break;
    }
    startActivity(intent);
}

}


#### 二.隐示Intent


##### 采用隐示Intent打开另一个activity


在项目的AndroidManifest.xml中为activity添加




将MainActivity中



intent.setClassName(this,“com.example.buttondemo.DateActivity”);


修改为



intent.setAction(“li.tech.dateActivity”);
intent.addCategory(Intent.CATEGORY_DEFAULT);


#### 三.参考链接


<https://blog.csdn.net/qq_48008050/article/details/114804005>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值