安卓开发学习之设计三种计算机界面

简介: 设计三种计算机界面

## 请设计下面的三种计算器的UI:


1.简单的计算器

caculator1.png



2.科学计算器

caculator2.png



3.程序计算器

caculator3.png

不用实现具体功能,只需设计界面即可!

### 为了更好的在三个界面之间跳转,添加一个主界面。

#### activity_main.xml

线性布局中添加4个按钮


```xml

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

<androidx.constraintlayout.widget.ConstraintLayout 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"

   tools:context=".MainActivity">



   <LinearLayout

       android:layout_width="431dp"

       android:layout_height="669dp"

       android:orientation="vertical"

       tools:ignore="MissingConstraints"

       tools:layout_editor_absoluteX="-4dp"

       tools:layout_editor_absoluteY="57dp">



       <Button

           android:id="@+id/button21"

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:text="简单计算器" />


       <Button

           android:id="@+id/button22"

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:text="科学计算器" />


       <Button

           android:id="@+id/button23"

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:text="程序计算器" />


       <Button

           android:id="@+id/button24"

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:text="退出" />


   </LinearLayout>



</androidx.constraintlayout.widget.ConstraintLayout>

```

#### 界面效果:

屏幕截图 2022-04-06 180941.png

### 简单计算器:

#### chengxujishuanqi.xml


```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"

   android:orientation="vertical"

   android:layout_width="match_parent"

   android:layout_height="match_parent"

   android:weightSum="7">


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="vertical">


       <TextView

           android:layout_width="match_parent"

           android:layout_height="match_parent"

           android:gravity="center|right"

           android:text="0"

           android:textSize="50sp" />


   </LinearLayout>


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:orientation="horizontal"

       android:layout_weight="1"

       android:weightSum="4">


       <Button

           android:id="@+id/button1"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="退格"

           android:textSize="30sp" />


       <Button

           android:id="@+id/button2"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="清除"

           android:textSize="30sp" />


       <Button

           android:id="@+id/button3"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="±"

           android:textSize="40sp" />


       <Button

           android:id="@+id/button4"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="+"

           android:textSize="40sp" />

   </LinearLayout>


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:layout_weight="1"

       android:orientation="horizontal"

       android:weightSum="4">


       <Button

           android:id="@+id/button5"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="7"

           android:textSize="40sp" />


       <Button

           android:id="@+id/button6"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="8"

           android:textSize="40sp" />


       <Button

           android:id="@+id/button7"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="9"

           android:textSize="40sp" />


       <Button

           android:id="@+id/button8"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="—"

           android:textSize="40sp" />

   </LinearLayout>


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:layout_weight="1"

       android:orientation="horizontal"

       android:weightSum="4">


       <Button

           android:id="@+id/button9"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="4"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button10"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="5"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button11"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="6"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button12"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="*"

           android:textSize="40sp"/>

   </LinearLayout>


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:layout_weight="1"

       android:orientation="horizontal"

       android:weightSum="4">


       <Button

           android:id="@+id/button13"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="1"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button14"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="2"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button15"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="3"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button16"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="/"

           android:textSize="40sp"/>

   </LinearLayout>


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="wrap_content"

       android:layout_weight="1"

       android:orientation="horizontal"

       android:weightSum="4">


       <Button

           android:id="@+id/button17"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="0"

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button18"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="."

           android:textSize="40sp"/>


       <Button

           android:id="@+id/button19"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="1/x"

           android:textSize="30sp"/>


       <Button

           android:id="@+id/button20"

           android:layout_width="0dp"

           android:layout_height="match_parent"

           android:layout_weight="1"

           android:text="="

           android:textSize="40sp"/>

   </LinearLayout>


</LinearLayout>

```

#### 界面效果:

屏幕截图 2022-04-06 181648.png




### 科学计算器:

#### kexuejishuanqi.xml


```xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:orientation="vertical" android:layout_width="match_parent"

   android:layout_height="match_parent">


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="match_parent"

       android:orientation="vertical">


       <TextView

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:gravity="center|right"

           android:text="0"

           android:textSize="50sp"/>


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="21dp"

           android:layout_margin="10dp"

           android:padding="0dp">


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="wrap_content">


               <RadioGroup

                   android:layout_width="match_parent"

                   android:layout_height="wrap_content"

                   android:layout_weight="1"

                   android:orientation="horizontal">


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="角度"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="弧度"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="梯度"

                       android:textSize="15dp" />

               </RadioGroup>

           </TableRow>


       </TableLayout>


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="215dp">


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="SIN" />


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="COS" />


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="TAN" />


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="COT"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ASIN"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ACOS"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ATAN"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ACOT"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="SINH"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="COSH"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="TANH"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="COTH"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ASINH"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ACOSH"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ATANH"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="ACOTH"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="LN"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="LOG10"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="N!"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="X^Y"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="E^X"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="π"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="("></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text=")"></Button>



           </TableRow>



       </TableLayout>


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="186dp">


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="退格"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="清除"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="±"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="+"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="7"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="8"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="9"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="-"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="4"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="5"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="6"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="*"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="1"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="2"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="3"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="/"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="0"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="."></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="1/X"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="="></Button>



           </TableRow>



       </TableLayout>


   </LinearLayout>


</LinearLayout>

```


#### 界面效果:

屏幕截图 2022-04-06 181724.png



### 程序计算器:

#### chengxujishuanqi.xml


```xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

   android:orientation="vertical" android:layout_width="match_parent"

   android:layout_height="match_parent">


   <LinearLayout

       android:layout_width="match_parent"

       android:layout_height="match_parent"

       android:orientation="vertical">


       <TextView

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:gravity="center|right"

           android:text="0"

           android:textSize="50sp" />


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="21dp"

           android:layout_margin="10dp"

           android:padding="0dp">


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="wrap_content">


               <RadioGroup

                   android:layout_width="match_parent"

                   android:layout_height="wrap_content"

                   android:layout_weight="1"

                   android:orientation="horizontal">


                   <RadioButton

                       android:layout_width="76dp"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="十六进制"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="二进制"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="八进制"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="十进制"

                       android:textSize="15dp" />

               </RadioGroup>

           </TableRow>


       </TableLayout>


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="21dp"

           android:layout_margin="10dp"

           android:padding="0dp">


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="wrap_content">


               <RadioGroup

                   android:layout_width="match_parent"

                   android:layout_height="wrap_content"

                   android:layout_weight="1"

                   android:orientation="horizontal">


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="八字节"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="四字节"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="二字节"

                       android:textSize="15dp" />


                   <RadioButton

                       android:layout_width="wrap_content"

                       android:layout_height="wrap_content"

                       android:layout_weight="1"

                       android:text="单字节"

                       android:textSize="15dp" />

               </RadioGroup>

           </TableRow>


       </TableLayout>



       <GridLayout

           android:layout_width="match_parent"

           android:layout_height="wrap_content"

           android:columnCount="4"

           android:orientation="horizontal"

           android:rowCount="3">


           <Button

               android:layout_width="102dp"

               android:layout_height="match_parent"

               android:text="NOT"

               android:textColor="#FBF9F9" />


           <Button

               android:layout_width="103dp"

               android:layout_height="match_parent"

               android:text="AND" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="OR" />


           <Button

               android:layout_width="99dp"

               android:layout_height="match_parent"

               android:text="XOR" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="循环左移" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="循环右移" />


           <Button

               android:layout_width="104dp"

               android:layout_height="match_parent"

               android:text="左移" />


           <Button

               android:layout_width="102dp"

               android:layout_height="match_parent"

               android:text="MOD" />


           <Button

               android:layout_columnSpan="2"

               android:layout_gravity="fill"

               android:text="无符号右移" />


           <Button

               android:layout_width="wrap_content"

               android:layout_columnSpan="2"

               android:layout_gravity="fill"

               android:text="有符号右移" />



       </GridLayout>


       <TableLayout

           android:layout_width="match_parent"

           android:layout_height="212dp">


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="退格"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="清除"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="9"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="±"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="6"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="7"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="8"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="+"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="3"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="4"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="5"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="+"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="0"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="1"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="2"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="/"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="A"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="B"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="C"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="D"></Button>



           </TableRow>


           <TableRow

               android:layout_width="match_parent"

               android:layout_height="487dp"

               android:layout_weight="1"

               android:padding="0dp">


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="E"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="F"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="G"></Button>


               <Button

                   android:layout_height="match_parent"

                   android:layout_weight="1"

                   android:text="="></Button>



           </TableRow>




       </TableLayout>


   </LinearLayout>


</LinearLayout>

```


#### 界面效果:


屏幕截图 2022-04-06 181747.png





### 主界面和其他界面的交互

点击对应的按钮,跳转相应的界面!

#### MainActivity


```java

package com.example.myapplication;


import androidx.appcompat.app.AppCompatActivity;


import android.content.Intent;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.widget.Button;


public class MainActivity extends AppCompatActivity {


   @Override

   protected void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

       Button btn1=(Button) findViewById(R.id.button21);

       Button btn2=(Button) findViewById(R.id.button22);

       Button btn3=(Button) findViewById(R.id.button23);

       Button btn4=(Button) findViewById(R.id.button24);

       btn1.setOnClickListener(new View.OnClickListener(){

           @Override

           public  void onClick(View View){

               setContentView(R.layout.jiandanjishuanqi);

           }

       });

       btn2.setOnClickListener(new View.OnClickListener(){

           @Override

           public  void onClick(View View){

               setContentView(R.layout.kexuejishuanqi);

           }

       });

       btn3.setOnClickListener(new View.OnClickListener(){

           @Override

           public  void onClick(View View){

               setContentView(R.layout.chengxujishuanqi);

           }

       });

       btn4.setOnClickListener(new View.OnClickListener(){

               @Override

               public  void onClick(View View){

                   System.exit(0);

       }


       });

   }

   @Override

   public  boolean onKeyDown(int keyCode, KeyEvent event){

       if(keyCode==KeyEvent.KEYCODE_BACK){

           Intent intent=new Intent(this,MainActivity.class);

           intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

           startActivity(intent);

       }

       return  true;

   }

}

```

### 总结:

安卓实验作业,刚接触能力有限就做了个大概,可以根据自己的需求添加主题,样式,颜色!




目录
相关文章
|
1月前
|
移动开发 前端开发 Android开发
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
235 12
【02】建立各项目录和页面标准化产品-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
1月前
|
移动开发 JavaScript 应用服务中间件
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
203 5
【06】优化完善落地页样式内容-精度优化-vue加vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
1月前
|
移动开发 Rust JavaScript
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
514 4
【01】首页建立-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
|
2月前
|
开发工具 Android开发
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
480 11
X Android SDK file not found: adb.安卓开发常见问题-Android SDK 缺少 `adb`(Android Debug Bridge)-优雅草卓伊凡
|
1月前
|
移动开发 Android开发
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
【03】建立隐私关于等相关页面和内容-vue+vite开发实战-做一个非常漂亮的APP下载落地页-支持PC和H5自适应提供安卓苹果鸿蒙下载和网页端访问-优雅草卓伊凡
120 0
|
2月前
|
Java 开发工具 Maven
【01】完整的安卓二次商业实战-详细的初级步骤同步项目和gradle配置以及开发思路-优雅草伊凡
【01】完整的安卓二次商业实战-详细的初级步骤同步项目和gradle配置以及开发思路-优雅草伊凡
196 6
|
4月前
|
安全 数据库 Android开发
在Android开发中实现两个Intent跳转及数据交换的方法
总结上述内容,在Android开发中,Intent不仅是活动跳转的桥梁,也是两个活动之间进行数据交换的媒介。运用Intent传递数据时需注意数据类型、传输大小限制以及安全性问题的处理,以确保应用的健壯性和安全性。
354 11
|
4月前
|
移动开发 Java 编译器
Kotlin与Jetpack Compose:Android开发生态的演进与架构思考
本文从资深Android工程师视角深入分析Kotlin与Jetpack Compose在Android系统中的技术定位。Kotlin通过空安全、协程等特性解决了Java在移动开发中的痛点,成为Android官方首选语言。Jetpack Compose则引入声明式UI范式,通过重组机制实现高效UI更新。两者结合不仅提升开发效率,更为跨平台战略和现代架构模式提供技术基础,代表了Android开发生态的根本性演进。
177 0
|
8月前
|
JavaScript Linux 网络安全
Termux安卓终端美化与开发实战:从下载到插件优化,小白也能玩转Linux
Termux是一款安卓平台上的开源终端模拟器,支持apt包管理、SSH连接及Python/Node.js/C++开发环境搭建,被誉为“手机上的Linux系统”。其特点包括零ROOT权限、跨平台开发和强大扩展性。本文详细介绍其安装准备、基础与高级环境配置、必备插件推荐、常见问题解决方法以及延伸学习资源,帮助用户充分利用Termux进行开发与学习。适用于Android 7+设备,原创内容转载请注明来源。
1987 77
|
5月前
|
安全 Java Android开发
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡
265 0
为什么大厂要求安卓开发者掌握Kotlin和Jetpack?深度解析现代Android开发生态优雅草卓伊凡