久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2819|回復: 0
打印 上一主題 下一主題
收起左側

安卓java程序 對話框的使用

[復制鏈接]
跳轉到指定樓層
樓主
本帖最后由 dori 于 2020-12-18 23:15 編輯


layout文件夾的布局文件activity_main.xml中設計界面(快速注冊和忘記密碼為兩個TextView)
成功運行后將出現如下界面:
需新建一個xml文件,可命名為login


MainActivity.java文件:

package com.example.shiyan5;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //tv_quickReg是快速注冊文本框的id;login是彈出的快速注冊對話框的布局文件名
        TextView tv_quickReg = findViewById(R.id.tv_quickReg);
        tv_quickReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TableLayout loginForm = (TableLayout) getLayoutInflater()
                        .inflate(R.layout.login, null);
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setIcon(R.drawable.hat)
                        .setTitle("快速注冊")
                        .setView(loginForm)
                        .setNegativeButton("取消", null)
                        .setPositiveButton("確定", null)
                        .create().show();
            }
        });
//btn_exit是退出按鈕的id
        Button btn_exit = findViewById(R.id.btn_exit);
        btn_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setIcon(R.drawable.alert)
                        .setTitle("退出?")
                        .setMessage("確定要退出嗎?")
                        .setNegativeButton("取消", null)
                        .setPositiveButton("確定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        })
                        .create().show();
            }

        });
    }
}
activity_main.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:id="@+id/linearLayout2"
        android:layout_width="404dp"
        android:layout_height="130dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="3dp"
        app:layout_constraintBottom_toTopOf="@+id/tableRow3"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="156dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:srcCompat="@drawable/qq" />

        <LinearLayout
            android:layout_width="263dp"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="63dp">

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="91dp"
                    android:layout_height="match_parent"
                    android:text="                     用戶名:"
                    android:textColor="#E91E63"
                    android:textSize="20sp" />

                <EditText
                    android:id="@+id/editText"
                    android:layout_width="177dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/editext_selector"
                    android:ems="10"
                    android:gravity="start|top"
                    android:hint="                                            輸入用戶名"
                    android:inputType="textMultiLine" />

            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="63dp">

                <TextView
                    android:id="@+id/textView5"
                    android:layout_width="92dp"
                    android:layout_height="57dp"
                    android:text="                 密    碼:"
                    android:textColor="#E91E63"
                    android:textSize="20sp" />

                <EditText
                    android:id="@+id/editText2"
                    android:layout_width="178dp"
                    android:layout_height="match_parent"
                    android:background="@drawable/editext_selector"
                    android:ems="10"
                    android:gravity="start|top"
                    android:inputType="textMultiLine" />
            </TableRow>
        </LinearLayout>

    </LinearLayout>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="408dp"
        android:layout_height="73dp"
        android:layout_marginTop="3dp"
        android:layout_marginEnd="4dp"
        android:layout_marginRight="4dp"
        app:layout_constraintBottom_toTopOf="@+id/tableRow4"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

        <CheckBox
            android:id="@+id/checkBox"
            android:layout_width="192dp"
            android:layout_height="match_parent"
            android:text="記住密碼"
            android:textSize="20sp" />

        <CheckBox
            android:id="@+id/checkBox2"
            android:layout_width="214dp"
            android:layout_height="73dp"
            android:text="自動登錄"
            android:textSize="20sp" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="410dp"
        android:layout_height="44dp"
        android:layout_marginEnd="2dp"
        android:layout_marginRight="2dp"
        app:layout_constraintBottom_toTopOf="@+id/tableRow5"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tableRow3">

        <TextView
            android:id="@+id/tv_quickReg"
            android:layout_width="192dp"
            android:layout_height="wrap_content"
            android:text="    快速注冊"
            android:textColor="#009688"
            android:textSize="30sp" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="217dp"
            android:layout_height="wrap_content"
            android:text="    忘記密碼"
            android:textColor="#009688"
            android:textSize="30sp" />
    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="409dp"
        android:layout_height="63dp"
        android:layout_marginEnd="3dp"
        android:layout_marginRight="3dp"
        android:layout_marginBottom="338dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tableRow4">

        <Button
            android:id="@+id/btn_exit"
            android:layout_width="192dp"
            android:layout_height="match_parent"
            android:text="退出"
            android:textSize="30sp" />

        <Button
            android:id="@+id/button2"
            android:layout_width="215dp"
            android:layout_height="63dp"
            android:text="登錄"
            android:textSize="30sp" />
    </TableRow>

</androidx.constraintlayout.widget.ConstraintLayout>
login.xml文件:<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableRow
        android:layout_width="400dp"
        android:layout_height="102dp">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="郵箱:"
            android:textColor="#E91E63"
            android:textSize="30sp" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="284dp"
            android:layout_height="55dp"
            android:background="@drawable/editext_selector"
            android:ems="10"
            android:gravity="start|top"
            android:inputType="textMultiLine" />

    </TableRow>

    <TableRow
        android:layout_width="400dp"
        android:layout_height="102dp">

        <TextView
            android:id="@+id/textView4"
            android:layout_width="127dp"
            android:layout_height="match_parent"
            android:text="密碼:"
            android:textColor="#E91E63"
            android:textSize="30sp" />

        <EditText
            android:id="@+id/editText4"
            android:layout_width="284dp"
            android:layout_height="55dp"
            android:background="@drawable/editext_selector"
            android:ems="10"
            android:gravity="start|top"
            android:inputType="textMultiLine" />

    </TableRow>

</TableLayout>


對話框的使用.rar (8.58 MB, 下載次數: 7)





評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 免费v片| 国产伦精品一区二区三区照片91 | 国产一区二区免费 | 国产人久久人人人人爽 | 亚洲一区二区三区免费在线观看 | 全免费a级毛片免费看视频免费下 | 欧美精品一区三区 | 欧美黄色小视频 | 亚洲免费三区 | 中文字幕第二十页 | 免费激情 | 人人亚洲 | 在线看国产 | 91麻豆精品国产91久久久久久 | 久久久久国产精品一区二区 | 精品久久99 | 午夜免费观看体验区 | 中文字幕一区二区三区在线观看 | 亚洲精品三级 | 国产成人在线一区二区 | 久久久久国产一区二区三区四区 | 欧美激情视频一区二区三区免费 | 九九九久久国产免费 | 亚洲成人动漫在线观看 | 91精品国产91久久久久福利 | 成人精品国产一区二区4080 | 日日摸日日添日日躁av | 久久精品网 | 欧美一区久久 | 精品久久久久国产免费第一页 | www.久久.com| 国产精品高清一区二区三区 | 91伦理片 | 亚洲精品一区二区三区中文字幕 | a免费观看| 365夜爽爽欧美性午夜免费视频 | 一区二区在线免费观看视频 | 日韩羞羞 | 久久精品国产免费高清 | 91免费观看在线 | 99精品热视频|