Android Studio简单制作MKOPlayer音乐网站(封装成APP)小demo(日常作业练习)

 

 

Android Studio简单制作MKOPlayer音乐网站(封装成APP)小demo(日常作业练习)

 

 

                              ————安德风

 

 

一、最终效果展示:

 

 

 

二、界面布局设计:

1、首页界面布局设计activity_main.xml源代码

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:background="@drawable/dlandzc"
 8     tools:context=".MainActivity">
 9 
10     <ImageView
11         android:id="@+id/imageView"
12         android:layout_width="169dp"
13         android:layout_height="81dp"
14         android:layout_marginStart="16dp"
15         android:layout_marginLeft="16dp"
16         android:onClick="deluclick"
17         app:layout_constraintBottom_toBottomOf="parent"
18         app:layout_constraintStart_toStartOf="parent"
19         app:layout_constraintTop_toTopOf="parent"
20         app:layout_constraintVertical_bias="0.944"
21         app:srcCompat="@drawable/dl" />
22 
23     <ImageView
24         android:id="@+id/imageView2"
25         android:layout_width="194dp"
26         android:layout_height="86dp"
27         android:layout_marginStart="40dp"
28         android:layout_marginLeft="40dp"
29         android:onClick="zhucclick"
30         app:layout_constraintBottom_toBottomOf="parent"
31         app:layout_constraintStart_toEndOf="@+id/imageView"
32         app:layout_constraintTop_toTopOf="parent"
33         app:layout_constraintVertical_bias="0.944"
34         app:srcCompat="@drawable/zc" />
35 </androidx.constraintlayout.widget.ConstraintLayout>

2、注册界面布局设计activity_main2.xml源代码

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:layout_width="match_parent"
  6     android:layout_height="match_parent"
  7     android:background="@drawable/zcjm"
  8     tools:context=".Main2Activity">
  9 
 10     <EditText
 11         android:id="@+id/name"
 12         android:layout_width="wrap_content"
 13         android:layout_height="wrap_content"
 14         android:layout_marginTop="308dp"
 15         android:ems="10"
 16         android:hint="请输入用户名"
 17         android:inputType="textPersonName"
 18 
 19         android:textColorHint="#C3A476"
 20         android:textColorLink="#FF9800"
 21         app:layout_constraintEnd_toEndOf="parent"
 22         app:layout_constraintHorizontal_bias="0.484"
 23         app:layout_constraintStart_toStartOf="parent"
 24         app:layout_constraintTop_toTopOf="parent" />
 25 
 26     <EditText
 27         android:id="@+id/editText2"
 28         android:layout_width="wrap_content"
 29         android:layout_height="wrap_content"
 30         android:layout_marginTop="12dp"
 31         android:ems="10"
 32         android:hint="请输入密码"
 33         android:inputType="textPassword"
 34         android:textColorHint="#C3A476"
 35         app:layout_constraintEnd_toEndOf="parent"
 36         app:layout_constraintStart_toStartOf="parent"
 37         app:layout_constraintTop_toBottomOf="@+id/name" />
 38 
 39     <RadioGroup
 40         android:id="@+id/radioGroup"
 41         android:layout_width="wrap_content"
 42         android:layout_height="wrap_content"
 43         android:layout_marginStart="72dp"
 44         android:layout_marginLeft="72dp"
 45         android:layout_marginTop="56dp"
 46         app:layout_constraintStart_toStartOf="parent"
 47         app:layout_constraintTop_toBottomOf="@+id/editText2">
 48 
 49         <RadioButton
 50             android:id="@+id/radioButton2"
 51             android:layout_width="match_parent"
 52             android:layout_height="wrap_content"
 53             android:text=""
 54             android:textColor="#C3A476"
 55             android:textColorHint="#C3A476" />
 56 
 57         <RadioButton
 58             android:id="@+id/radioButton3"
 59             android:layout_width="match_parent"
 60             android:layout_height="wrap_content"
 61             android:text=""
 62             android:textColor="#C3A476" />
 63     </RadioGroup>
 64 
 65     <TextView
 66         android:id="@+id/textView"
 67         android:layout_width="wrap_content"
 68         android:layout_height="wrap_content"
 69         android:layout_marginStart="72dp"
 70         android:layout_marginLeft="72dp"
 71         android:layout_marginTop="24dp"
 72         android:text="性别:"
 73         android:textColor="#C3A476"
 74         app:layout_constraintStart_toStartOf="parent"
 75         app:layout_constraintTop_toBottomOf="@+id/editText2" />
 76 
 77     <TextView
 78         android:id="@+id/textView2"
 79         android:layout_width="wrap_content"
 80         android:layout_height="wrap_content"
 81         android:layout_marginStart="56dp"
 82         android:layout_marginLeft="56dp"
 83         android:layout_marginTop="16dp"
 84         android:text="兴趣爱好:"
 85         android:textColor="#C3A476"
 86         app:layout_constraintStart_toStartOf="parent"
 87         app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
 88 
 89     <CheckBox
 90         android:id="@+id/checkBox"
 91         android:layout_width="wrap_content"
 92         android:layout_height="wrap_content"
 93         android:layout_marginStart="72dp"
 94         android:layout_marginLeft="72dp"
 95         android:layout_marginTop="20dp"
 96         android:text="编程"
 97         android:textColor="#C3A476"
 98         app:layout_constraintStart_toStartOf="parent"
 99         app:layout_constraintTop_toBottomOf="@+id/textView2" />
100 
101     <CheckBox
102         android:id="@+id/checkBox2"
103         android:layout_width="wrap_content"
104         android:layout_height="wrap_content"
105         android:layout_marginStart="8dp"
106         android:layout_marginLeft="8dp"
107         android:layout_marginTop="176dp"
108         android:text="唱歌"
109         android:textColor="#C3A476"
110         app:layout_constraintStart_toEndOf="@+id/checkBox"
111         app:layout_constraintTop_toBottomOf="@+id/editText2" />
112 
113     <CheckBox
114         android:id="@+id/checkBox3"
115         android:layout_width="wrap_content"
116         android:layout_height="wrap_content"
117         android:layout_marginStart="8dp"
118         android:layout_marginLeft="8dp"
119         android:layout_marginTop="176dp"
120         android:text="跳舞"
121         android:textColor="#C3A476"
122         app:layout_constraintStart_toEndOf="@+id/checkBox2"
123         app:layout_constraintTop_toBottomOf="@+id/editText2" />
124 
125     <ImageView
126         android:id="@+id/zhuce1"
127         android:layout_width="235dp"
128         android:layout_height="62dp"
129         android:layout_marginTop="644dp"
130         android:onClick="zc1"
131         app:layout_constraintEnd_toEndOf="parent"
132         app:layout_constraintHorizontal_bias="0.42"
133         app:layout_constraintStart_toStartOf="parent"
134         app:layout_constraintTop_toTopOf="parent"
135         app:srcCompat="@drawable/zhuc" />
136 
137 </androidx.constraintlayout.widget.ConstraintLayout>

3、登录界面布局设计activity_main2.xml源代码

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:background="@drawable/dljm"
 8     tools:context=".Main3Activity">
 9 
10     <EditText
11         android:id="@+id/et"
12         android:layout_width="wrap_content"
13         android:layout_height="wrap_content"
14         android:layout_marginTop="308dp"
15         android:ems="10"
16         android:hint="请输入用户名"
17         android:inputType="textPersonName"
18         android:textColorHint="#C3A476"
19         app:layout_constraintEnd_toEndOf="parent"
20         app:layout_constraintStart_toStartOf="parent"
21         app:layout_constraintTop_toTopOf="parent" />
22 
23     <EditText
24         android:id="@+id/editText3"
25         android:layout_width="wrap_content"
26         android:layout_height="wrap_content"
27         android:layout_marginTop="12dp"
28         android:ems="10"
29         android:hint="请输入密码"
30         android:inputType="textPassword"
31         android:textColorHint="#C3A476"
32         app:layout_constraintEnd_toEndOf="parent"
33         app:layout_constraintStart_toStartOf="parent"
34         app:layout_constraintTop_toBottomOf="@+id/et" />
35 
36     <ImageView
37         android:id="@+id/dlu2"
38         android:layout_width="wrap_content"
39         android:layout_height="wrap_content"
40         android:layout_marginTop="84dp"
41         android:onClick="dl"
42         app:layout_constraintEnd_toEndOf="parent"
43         app:layout_constraintHorizontal_bias="0.496"
44         app:layout_constraintStart_toStartOf="parent"
45         app:layout_constraintTop_toBottomOf="@+id/editText3"
46         app:srcCompat="@drawable/dlu2" />
47 
48     <TextView
49         android:id="@+id/textView3"
50         android:layout_width="wrap_content"
51         android:layout_height="wrap_content"
52         android:layout_marginTop="20dp"
53         android:onClick="wjmm"
54         android:text="忘记密码"
55         android:textColor="#C3A476"
56         android:textSize="24sp"
57         app:layout_constraintEnd_toEndOf="parent"
58         app:layout_constraintHorizontal_bias="0.873"
59         app:layout_constraintStart_toStartOf="parent"
60         app:layout_constraintTop_toBottomOf="@+id/editText3" />
61 </androidx.constraintlayout.widget.ConstraintLayout>

三、手机上方显示状态栏颜色更改R/values/color.xml

 

1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3     <color name="colorPrimary">#FFC444</color>
4     <color name="colorPrimaryDark">#FFC444</color>
5     <color name="colorAccent">#FFC444</color>
6 </resources>

 

四、模块标题栏中标题更改R/values/String.xml

 1 <resources> 2 <string name="app_name">MKOPlayer</string> 3 </resources> 

五、功能实现

1、首页功能实现MainActivity.java

 1 package com.example.adf;
 2 
 3 import androidx.appcompat.app.AppCompatActivity;
 4 
 5 import android.content.Intent;
 6 import android.os.Bundle;
 7 import android.view.View;
 8 
 9 public class MainActivity extends AppCompatActivity {
10 
11     @Override
12     protected void onCreate(Bundle savedInstanceState) {
13         super.onCreate(savedInstanceState);
14         setContentView(R.layout.activity_main);
15     }
16 
17     public void deluclick(View view) {
18         Intent intent=new Intent(MainActivity.this,Main3Activity.class);
19         startActivity(intent);
20 
21     }
22 
23     public void zhucclick(View view) {
24         Intent intent=new Intent(MainActivity.this,Main2Activity.class);
25         startActivity(intent);
26     }
27 }

2、注册界面功能实现Main2Activity.java

 1 package com.example.adf;
 2 
 3 import androidx.appcompat.app.AppCompatActivity;
 4 
 5 import android.content.Intent;
 6 import android.os.Bundle;
 7 import android.view.View;
 8 import android.widget.EditText;
 9 import android.widget.ImageView;
10 import android.widget.Toast;
11 
12 public class Main2Activity extends AppCompatActivity {
13 EditText name,pwd;
14 ImageView zhuce1;
15 
16     @Override
17     protected void onCreate(Bundle savedInstanceState) {
18         super.onCreate(savedInstanceState);
19         setContentView(R.layout.activity_main2);
20 
21         name=findViewById(R.id.name);
22         pwd=findViewById(R.id.editText2);
23         zhuce1=findViewById(R.id.zhuce1);
24 
25 
26     }
27 
28     public void zc1(View view) {
29         String username=name.getText().toString();
30         String password=pwd.getText().toString();
31         if (username.equals("")||password.equals("")){
32             Toast.makeText(this, "抱歉,注册失败,用户名或者密码不能为空;请补充完整", Toast.LENGTH_SHORT).show();
33         }
34         else{
35 
36             Intent intent=new Intent(Main2Activity.this,Main3Activity.class);
37             intent.putExtra("username",username);
38             intent.putExtra("password",password);
39             startActivity(intent);
40 
41         }
42     }
43 }

3、登录界面功能实现Main3Activity.java

 1 package com.example.adf;
 2 
 3 import androidx.appcompat.app.AppCompatActivity;
 4 
 5 import android.content.Intent;
 6 import android.net.Uri;
 7 import android.os.Bundle;
 8 import android.view.View;
 9 import android.widget.EditText;
10 import android.widget.ImageView;
11 import android.widget.TextView;
12 import android.widget.Toast;
13 
14 public class Main3Activity extends AppCompatActivity {
15 EditText et1,et2;
16 ImageView dlu2;
17     @Override
18     protected void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20         setContentView(R.layout.activity_main3);
21 
22 
23         et1=findViewById(R.id.et);
24         et2=findViewById(R.id.editText3);
25         dlu2=findViewById(R.id.dlu2);
26 
27 
28     }
29 
30     public void dl(View view) {
31         String  mingzi=et1.getText().toString();
32         String  mima=et2.getText().toString();
33         Intent intent=getIntent();
34         String uer=intent.getStringExtra("username");
35         String pwd =intent.getStringExtra("password");
36         if (mingzi.equals(uer)&&mima.equals(pwd)){
37 //            Toast.makeText(this, "恭喜您 ,登录成功", Toast.LENGTH_SHORT).show();
38 
39             Intent yitu=new Intent();
40             yitu.setAction(Intent.ACTION_VIEW);
41             yitu.setData(Uri.parse("http://www.quanbk.cn/yy"));
42             startActivity(yitu);
43 
44 
45 
46         }
47         else{
48             Toast.makeText(this, "抱歉!登录失败,请重新输入用户名或者密码", Toast.LENGTH_SHORT).show();
49         }
50 
51 
52     }
53 
54     public void wjmm(View view) {
55         Intent intent=new Intent(Main3Activity.this,Main2Activity.class);
56         startActivity(intent);
57     }
58 }

六、代码打包

链接:https://eyun.baidu.com/s/3o9Mtk2Q 密码:uihP

七、总结:

本次练习知识点回顾

1、如何通过一个activity跳转到另一个activity中(有两种方法:①显示方法②隐式方法)

2、从一个activity传送到另一个数据传送

3、Toast弹出框用法

我是安德风,以上就是本次练习所用到的核心知识点概括,感谢大家的观看,喜欢我的小伙伴欢迎关注与支持。有问题欢迎在下方留言;看到后一一答复。

 

 

猜你喜欢

转载自www.cnblogs.com/adf520/p/12610773.html
今日推荐