用android studio写一个简单的记单词?????App

简介: 用android studio写一个简单的记单词?????App

 一个贼贼简单的APP,按照前端来说,就只是实现了几个页面跳转和点击事件,数据库链接都没用到。就这么几个简单的页面和跳转,各位见笑了。

看一下效果吧:

页面设计(activity_main):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@mipmap/pp1"
    tools:context=".MainActivity">
    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:text="我爱安卓"
        android:textColor="#000000 "
        android:textSize="18sp"
        android:layout_gravity="center"
        android:layout_marginTop="160dp"
         />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="欢迎登入,hello"
        android:textColor="#FF5722"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
   <EditText
       android:id="@+id/et_1"
       android:layout_width="match_parent"
       android:layout_height="50dp"
       android:textSize="16sp"
       android:textColor="@color/colorBlack"
      android:hint="用户名:"
       android:maxLines="1"
       android:padding="5dp"
       android:layout_marginTop="8dp"
       android:background="@drawable/bb_username"
       />
    <EditText
        android:id="@+id/et_2"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:textSize="16sp"
        android:textColor="@color/colorBlack"
        android:hint="密码:"
        android:maxLines="1"
        android:padding="5dp"
        android:inputType="textPassword"
        android:layout_marginTop="6dp"
        android:background="@drawable/bb_username"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="20dp"
>
        <Button
            android:id="@+id/btn_login"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:background="@drawable/bbn_1left"
            android:textColor="#000000"
            android:text="登入" />
        <Button
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="注册"
            android:layout_marginLeft="2dp"
            android:background="@drawable/bbn_1right"
            android:textColor="#000000"
            />
    </LinearLayout>
</LinearLayout>

java(MainActivity):

package com.example.jdcapp;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import com.example.jdcapp.util.ToastUtil;
public class MainActivity extends  AppCompatActivity implements View.OnClickListener {
    //声明控件
    private Button mBtnLogin;
    private EditText mEtUser;
    private  EditText mEtPassword;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //找到控件
        mBtnLogin = findViewById(R.id.btn_login);
        mEtUser = findViewById(R.id.et_1);
        mEtPassword = findViewById(R.id.et_2);
//    //实现跳转
//    mBtnLogin.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//            Intent intent =null;
//            intent = new Intent(MainActivity.this,SlideActivity.class);
//            startActivity(intent);
//        }
//    });
        mBtnLogin.setOnClickListener(this);
    }
    public void onClick(View v){
        //需要获取用户名和密码
        String username = mEtUser.getText().toString();
        String password = mEtPassword.getText().toString();
        //弹出的内容设置
        String ok = "登入成功";
        String fail = "密码或者账号有误,请重新输入";
        Intent intent = null ;
        //假设正确的账号是ttk,密码是 123456
        if(username.equals("ttj")&&password.equals("123456")){
            //封装好的类
            ToastUtil.showMsg(MainActivity.this,ok);
            //如果正确的话进行跳转
            intent = new Intent(MainActivity.this,SlideActivity.class);
            startActivity(intent);
        }
        else{
//         Toast toastCenter = Toast.makeText(getApplicationContext(),fail,Toast.LENGTH_SHORT);
//         toastCenter.setGravity(Gravity.CENTER,0,0);
//         toastCenter.show();
            ToastUtil.showMsg(MainActivity.this,fail);
        }
    }
    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
    }
}

用户名和密码是写死的: 用户名:ttj  密码:123456  

页面设计(activity_slide):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@mipmap/tp2"
    tools:context=".SlideActivity">
    <TextView
        android:id="@+id/vt_gunc_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="主界面"
        android:textSize="30sp"
        android:gravity="center"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="选择学习类型"
        android:gravity="center"
        android:layout_marginTop="150dp"
        android:textColor="#000000"/>
    <Button
        android:id="@+id/xfw_1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="安卓发展史"
        android:gravity="center"
        android:layout_marginLeft="10dp"
        android:background="@drawable/bb_username"
        android:textColor="#000000"
        />
    <Button
        android:id="@+id/xfw_2"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="安卓语法"
        android:gravity="center"
        android:layout_marginLeft="10dp"
        android:background="@drawable/bb_username"
        android:textColor="#000000"
        />
    <Button
        android:id="@+id/xfw_3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="安卓基本常识"
        android:gravity="center"
        android:layout_marginLeft="10dp"
        android:background="@drawable/bb_username"
        android:textColor="#000000"
        />
    <Button
        android:id="@+id/xfw_4"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="安卓小测试"
        android:gravity="center"
        android:layout_marginLeft="10dp"
        android:background="@drawable/bb_username"
        android:textColor="#000000"
        />
</LinearLayout>

java(SlideActivity):

package com.example.jdcapp;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class SlideActivity extends AppCompatActivity {
    //声明控件
    private  Button mBhistory;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide);
        //找到控件
        mBhistory = findViewById(R.id.xfw_1);
        //实现跳转
        mBhistory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = null ;
                intent = new Intent(SlideActivity.this,function1Activity.class);
                startActivity(intent);
            }
        });
    }
}

页面设计(activity_function1.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".function1Activity">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="下面是安卓的发展历史"
        android:textSize="30sp"
        android:gravity="center"
        android:textColor="#DF1157"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="320dp"
        android:text="  2003年10月,Andy Rubin等人创建Android公司,并组建Android团队。2005年8月17日,Google低调收购了成立仅22个月的高科技企业Android及其团队。安迪鲁宾成为Google公司工程部副总裁,继续负责Android项目。
2007年11月5日,谷歌公司正式向外界展示了这款名为Android的操作系统。直到2011年1月,谷歌称每日的Android设备新用户数量达到了30万部,到2011年7月,这个数字增长到55万部,而Android系统设备的用户总数达到了1.35亿,Android系统已经成为智能手机领域占有量最高的系统。"
        android:textSize="20sp"
        android:textColor="#000000"
        />
 <TextView
     android:layout_width="match_parent"
     android:layout_height="40dp"
     android:text="小练习:下面哪个是Android标志呢????"
     android:textSize="20sp"
     android:padding="5dp"
     android:textColor="#068006"
     />
   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       >
    <ImageView
        android:id="@+id/iv_an"
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:src="@mipmap/tp9"
        />
        <ImageView
            android:id="@+id/iv_an2"
            android:layout_width="90dp"
            android:layout_height="70dp"
            android:src="@mipmap/tp3"
            />
       <ImageView
           android:layout_width="90dp"
           android:layout_height="70dp"
           android:src="@mipmap/tp5"
           />
       <ImageView
           android:layout_width="90dp"
           android:layout_height="70dp"
           android:src="@mipmap/tp8"
           />
   </LinearLayout>
</LinearLayout>

java(function1Activity):

package com.example.jdcapp;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class function1Activity extends AppCompatActivity {
    private ImageView Iman;
    private ImageView Iman2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_function1);
        Iman = findViewById(R.id.iv_an);
        Iman2 = findViewById(R.id.iv_an2);
        Iman.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =null;
                intent = new Intent(function1Activity.this, com.example.jdcapp.function11Activity.class);
                startActivity(intent);
            }
        });
        Iman2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =null;
                intent = new Intent(function1Activity.this,funnn.class);
                startActivity(intent);
            }
        });
}
}

页面设计(activity_function11.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@mipmap/pp1"
    tools:context=".function11Activity">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text=" 恭喜答对了!!!"
        android:textSize="30sp"
        android:gravity="center"
        android:textColor="#DF1157"
        android:layout_marginTop="200dp"
        />
    <ImageView
        android:id="@+id/iv_apple"
        android:layout_width="90dp"
        android:layout_height="70dp"
        android:src="@mipmap/tp9"
        />
</LinearLayout>

java(function11Activity ):

package com.example.jdcapp;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class function11Activity extends AppCompatActivity {
    private ImageView Iman;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_function11);
       // Iman = findViewById(R.id.iv_apple);
//        Iman.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent =null;
//                intent = new Intent(function11Activity.this,funnn.class);
//                startActivity(intent);
//            }
//        });
    }
}

别忘了配置AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.jdcapp">
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.JDCApp"
        tools:targetApi="31">
        <activity android:name=".function11Activity" />
        <activity android:name=".function1Activity" />
        <activity android:name=".SlideActivity" />
        <activity android:name=".funnn" />
        <activity android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

最后就是用到的样式和目录结构:

bb_username.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
    android:width="2dp"
    android:color="@color/colorBlack"
    />
<corners
    android:radius="50dp"
    />
    <solid
        android:color="#00000000"
        />
</shape>

bbn_1left.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
    android:width="2dp"
    android:color="@color/colorBlack"
    />
<corners
    android:topLeftRadius="150dp"
    android:bottomLeftRadius="150dp"
    />
    <solid
        android:color="#00000000"
        />
</shape>

bbn_1right.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
    android:width="2dp"
    android:color="@color/colorBlack"
    />
<corners
    android:topRightRadius="5dp"
    android:bottomRightRadius="5dp"
    />
    <solid
        android:color="#00000000"
        />
</shape>

相关文章
|
2月前
|
Java Android开发 C++
Android Studio JNI 使用模板:c/cpp源文件的集成编译,快速上手
本文提供了一个Android Studio中JNI使用的模板,包括创建C/C++源文件、编辑CMakeLists.txt、编写JNI接口代码、配置build.gradle以及编译生成.so库的详细步骤,以帮助开发者快速上手Android平台的JNI开发和编译过程。
91 1
|
20天前
|
Java 数据库 Android开发
一个Android App最少有几个线程?实现多线程的方式有哪些?
本文介绍了Android多线程编程的重要性及其实现方法,涵盖了基本概念、常见线程类型(如主线程、工作线程)以及多种多线程实现方式(如`Thread`、`HandlerThread`、`Executors`、Kotlin协程等)。通过合理的多线程管理,可大幅提升应用性能和用户体验。
35 15
一个Android App最少有几个线程?实现多线程的方式有哪些?
|
7天前
|
存储 开发工具 Android开发
使用.NET MAUI开发第一个安卓APP
【9月更文挑战第24天】使用.NET MAUI开发首个安卓APP需完成以下步骤:首先,安装Visual Studio 2022并勾选“.NET Multi-platform App UI development”工作负载;接着,安装Android SDK。然后,创建新项目时选择“.NET Multi-platform App (MAUI)”模板,并仅针对Android平台进行配置。了解项目结构,包括`.csproj`配置文件、`Properties`配置文件夹、平台特定代码及共享代码等。
|
11天前
|
XML Android开发 数据格式
🌐Android国际化与本地化全攻略!让你的App走遍全球无障碍!🌍
在全球化背景下,实现Android应用的国际化与本地化至关重要。本文以一款旅游指南App为例,详细介绍如何通过资源文件拆分与命名、适配布局与方向、处理日期时间及货币格式、考虑文化习俗等步骤,完成多语言支持和本地化调整。通过邀请用户测试并收集反馈,确保应用能无缝融入不同市场,提升用户体验与满意度。
31 3
|
23天前
|
Java 数据库 Android开发
一个Android App最少有几个线程?实现多线程的方式有哪些?
本文介绍了Android应用开发中的多线程编程,涵盖基本概念、常见实现方式及最佳实践。主要内容包括主线程与工作线程的作用、多线程的多种实现方法(如 `Thread`、`HandlerThread`、`Executors` 和 Kotlin 协程),以及如何避免内存泄漏和合理使用线程池。通过有效的多线程管理,可以显著提升应用性能和用户体验。
38 10
|
23天前
|
XML IDE 开发工具
🔧Android Studio高级技巧大公开!效率翻倍,编码不再枯燥无味!🛠️
【9月更文挑战第11天】在软件开发领域,Android Studio凭借其强大的功能成为Android开发者的首选IDE。本文将揭示一些提升开发效率的高级技巧,包括自定义代码模板、重构工具、高级调试技巧及多模块架构。通过对比传统方法,这些技巧不仅能简化编码流程,还能显著提高生产力。例如,自定义模板可一键插入常用代码块;重构工具能智能分析并安全执行代码更改;高级调试技巧如条件断点有助于快速定位问题;多模块架构则提升了大型项目的可维护性和团队协作效率。掌握这些技巧,将使你的开发之旅更加高效与愉悦。
44 5
|
6天前
|
XML 数据库 Android开发
10分钟手把手教你用Android手撸一个简易的个人记账App
该文章提供了使用Android Studio从零开始创建一个简单的个人记账应用的详细步骤,包括项目搭建、界面设计、数据库处理及各功能模块的实现方法。
|
2月前
|
编解码 Android开发
【Android Studio】使用UI工具绘制,ConstraintLayout 限制性布局,快速上手
本文介绍了Android Studio中使用ConstraintLayout布局的方法,通过创建布局文件、设置控件约束等步骤,快速上手UI设计,并提供了一个TV Launcher界面布局的绘制示例。
37 1
|
2月前
|
Android开发
Android Studio: 解决Gradle sync failed 错误
本文介绍了解决Android Studio中出现的Gradle同步失败错误的步骤,包括从`gradle-wrapper.properties`文件中获取Gradle的下载链接,手动下载Gradle压缩包,并替换默认下载路径中的临时文件,然后重新触发Android Studio的"Try Again"来完成同步。
376 0
Android Studio: 解决Gradle sync failed 错误
|
2月前
|
Java Android开发 芯片
使用Android Studio导入Android源码:基于全志H713 AOSP,方便解决编译、编码问题
本文介绍了如何将基于全志H713芯片的AOSP Android源码导入Android Studio以解决编译和编码问题,通过操作步骤的详细说明,展示了在Android Studio中利用代码提示和补全功能快速定位并修复编译错误的方法。
48 0
使用Android Studio导入Android源码:基于全志H713 AOSP,方便解决编译、编码问题
下一篇
无影云桌面