Android开发

1.在Android studio上新建一个project,在一个Activity用三种显示Intent打开另一个Activity。并练习采用隐示Intent方式打开一个Activity

定义intent_filter(Androidmainfest.xml文件中)

 <activity android:name=".date">
            <intent-filter>
                <action android:name="qwert.date"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".clock">
        </activity>

更改点击按钮(mainactivity.java)

case R.id.type2_btn:
            intent.setAction("qwert.date");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            break;

2.设计一个APP,能实现一个简单的电话拨号,短信发送,照相机调用,地图打开的功能

发送短信

public class message extends AppCompatActivity {
    EditText num_btn;
    EditText mes_btn;
    Button send_btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        num_btn=(EditText) findViewById(R.id.num_btn);
        mes_btn=(EditText) findViewById(R.id.mes_btn);
        send_btn=(Button) findViewById(R.id.send_btn);
        send_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                String strPhoneNum = num_btn.getText().toString();
                Uri uri = Uri.parse("smsto:"+strPhoneNum);
                String strMsg = mes_btn.getText().toString();
                intent.setAction(Intent.ACTION_SENDTO);
                intent.setData(uri);
                intent.putExtra("sms_body", strMsg);
                startActivity(intent);`在这里插入代码片`
            }
        });
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

在这里插入图片描述
打开相机:

 case R.id.type3_btn:
                intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                break;

打开地图:

case R.id.type4_btn:
                Uri uri = Uri.parse("geo:39.9,116.3");
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(uri);
                break;

布局:

<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="电话"
        android:textColor="#ff0066"
        android:background="#00FFF7"
        android:id="@+id/type1_btn"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="短信"
        android:textColor="#00aaff"
        android:background="#00ff00"
        android:id="@+id/type2_btn"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="相机"
        android:textColor="#899ad5"
        android:background="#ff00ff"
        android:id="@+id/type3_btn"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="地图"
        android:textColor="#00ff00"
        android:background="#ff0066"
        android:id="@+id/type4_btn"/>

3.新建一个activity,测试它在启动其他activity,横竖屏变化时的生命周期

在这里插入图片描述
横竖屏变换
在这里插入图片描述
结果
在这里插入图片描述

界面如下所示,在添加多个学生信息包括(姓名、专业),后点击发送信息,在第二个界面上显示多个学生信息

在这里插入图片描述

页面布局:

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="学生信息"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.309"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.28" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="姓名"
        android:id="@+id/name_edit"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="专业"
        android:id="@+id/major_edit"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="发送信息"
            android:id="@+id/btn_save"
            android:layout_weight="1"/>
    </LinearLayout>

xml文件:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textSize="25sp"
        android:textColor="@color/teal_200"
        android:id="@+id/infoshow"/>

主代码部分:

public class MainActivity extends AppCompatActivity {
    Button btn_submit;
    Button btn_save;
    EditText name_edit;
    EditText major_edit;
    EditText age_edit;
    EditText score_edit;
    ArrayList<student> students=new ArrayList<student>();
    @Override
    protected  void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        name_edit=(EditText) findViewById(R.id.name_edit);
        major_edit=(EditText) findViewById(R.id.major_edit);
        age_edit=(EditText) findViewById(R.id.age_edit);
        score_edit=(EditText) findViewById(R.id.score_edit);
        btn_save=(Button) findViewById(R.id.btn_save);
        btn_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name=name_edit.getText().toString();
                String major=major_edit.getText().toString();
                int age=Integer.parseInt(age_edit.getText().toString());
                double score=Double.parseDouble(score_edit.getText().toString());
                student s=new student(name,major,age,score);
                students.add(s);
                name_edit.setText(" ");
                major_edit.setText(" ");
            }
        });
        btn_submit=(Button) findViewById(R.id.btn_submit);
        btn_submit.setOnClickListener(new View.OnClickListener()  {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,info.class);
                intent.putExtra("students",students);
                startActivity(intent);
            }
        });
    }
}
public class student implements Serializable{
    private String name;
    private String major;
    private int  age;
    private double score;
    student(String name,String major,int age,double score){
        this.name=name;
        this.major=major;
        this.age=age;
        this.score=score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {

        this.name = name;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public void setScore(double score) {
        this.score = score;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值