最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android超詳細(xì)介紹自定義多選框與點(diǎn)擊按鈕跳轉(zhuǎn)界面的實(shí)現(xiàn)

 更新時(shí)間:2022年03月26日 10:09:25   作者:DY.memory  
這篇文章主要介紹了在Android開(kāi)發(fā)中如何來(lái)實(shí)現(xiàn)自定義多選框以及如何實(shí)現(xiàn)點(diǎn)擊按鈕跳轉(zhuǎn)界面的功能,感興趣的朋友快來(lái)看看吧

總程:在avtivity_main.xml設(shè)計(jì)5個(gè)控件,btn1-5,點(diǎn)擊btn1彈出一個(gè)多選對(duì)話框,點(diǎn)擊按鈕btn1彈出一個(gè)多選框可選擇你喜歡的打野英雄,點(diǎn)擊btn2跳轉(zhuǎn)到activity_main2界面(就是圖片,不可選擇)設(shè)計(jì)思路流程:在activity_main.xml布局界面,總體在頭目錄進(jìn)行垂直排列,然后鑲嵌5個(gè)水平的線性布局(左是ImageView,右邊是Button按鈕)由于5張圖的大小在一個(gè)屏幕顯示不出來(lái),所以添加一個(gè)ScoveView滾動(dòng),以使所有資源可以看到!

在MainActivity.java對(duì)按鈕調(diào)用其id進(jìn)行監(jiān)聽(tīng),可見(jiàn)btn1.set......是彈出Multi多選對(duì)話框的功能,(如果不知道對(duì)話框的知識(shí)可以去了解,就是引用其類(lèi),設(shè)置相關(guān)屬性,title,icon,message等)然后把他show()出來(lái)。btn2.set.......是引入intent(用于綁定程序組件間的綁定,就是跳轉(zhuǎn)到不同的activity.java)相關(guān)知識(shí)點(diǎn)也可百度了解或者記住

btn2.setOnClickListener(new View.OnClickListener() {
    @Override public void onClick(View v) { 
    Intent intent=new Intent(MainActivity.this,Main2Activity.class); 
    startActivity(intent);
    } 
});

此代碼也可,btn2是你的按鈕id,MaineActivity是你new的empty activity,在其可設(shè)置要執(zhí)行的相關(guān)功能,也可不進(jìn)行設(shè)置(以實(shí)際情況功能而定)在activity_main2.xml布局你喜歡的界面,然后點(diǎn)擊按鈕2即可彈出,PS:一定要在迷你fest.xmlactivity,如果有不當(dāng)和錯(cuò)誤還望大佬和給位博主指出,讓我知道錯(cuò)誤點(diǎn),如果對(duì)你有所幫助就點(diǎn)個(gè)贊鼓勵(lì)一下把!

activity_main.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"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="#FFFFF123"
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="王者榮耀"
        android:gravity="center"
        android:textSize="35sp"
        android:textColor="#FFF35534"
        />
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
 
 
    <LinearLayout
 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
 
        <ImageView
            android:layout_width="180dp"
            android:layout_height="150dp"
            android:background="@drawable/dy"
 
            />
    <Button
 
        android:id="@+id/btn1"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:textSize="30sp"
        android:textColor="@color/colorAccent"
        android:text="點(diǎn)擊選擇你喜歡的王者榮耀打野英雄(文字形式)"
 
        />
    </LinearLayout>
    <LinearLayout
android:layout_marginTop="50dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
 
        <ImageView
            android:layout_width="180dp"
            android:layout_height="150dp"
            android:background="@drawable/ss"
 
            />
        <Button
 
            android:id="@+id/btn2"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:textSize="30sp"
            android:textColor="@color/colorAccent"
            android:text="點(diǎn)擊選擇你喜歡的王者榮耀上單英雄"
 
            />
    </LinearLayout>
    <LinearLayout
android:layout_marginTop="50dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
 
        <ImageView
            android:layout_width="180dp"
            android:layout_height="150dp"
            android:background="@drawable/sd"
 
            />
        <Button
 
            android:id="@+id/btn3"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:textSize="30sp"
            android:textColor="@color/colorAccent"
            android:text="點(diǎn)擊選擇你喜歡的王者榮耀射手英雄"
 
            />
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="50dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
 
        <ImageView
            android:layout_width="180dp"
            android:layout_height="150dp"
            android:background="@drawable/zl"
 
            />
        <Button
 
            android:id="@+id/btn4"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:textSize="30sp"
            android:textColor="@color/colorAccent"
            android:text="點(diǎn)擊選擇你喜歡的王者榮耀中路英雄"
            />
    </LinearLayout>
            <LinearLayout
                android:layout_marginTop="50dp"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
 
 
                <ImageView
                    android:layout_width="180dp"
                    android:layout_height="150dp"
                    android:background="@drawable/fz"
 
                    />
                <Button
 
                    android:id="@+id/btn5"
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:textSize="30sp"
                    android:textColor="@color/colorAccent"
                    android:text="點(diǎn)擊選擇你喜歡的王者榮耀輔助英雄"
                    />
            </LinearLayout>
</LinearLayout>
    </ScrollView>
</LinearLayout>

 MainActivity.java

package com.example.dialogapplication;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity  {
Button btn1,btn2,btn3;
String items[]={ "韓信", "李白", "凱" ,"娜可露露","孫悟空"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1=findViewById(R.id.btn1);
        btn2=findViewById(R.id.btn2);
        btn3=findViewById(R.id.btn3);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
                        dialog.setTitle("選擇你喜歡的王者榮耀打野英雄");
                            dialog .setIcon(R.drawable.wzrylogo);
                dialog.setPositiveButton("取消", null);
                                dialog.setPositiveButton("確定", null);
                       dialog.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
 
                            }
                        }).create();
                dialog.show();
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);
                startActivity(intent);
            }
        });
 
    }
}

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:textColor="@color/colorAccent"
                android:textSize="30sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="刺客:橘右京"
                android:gravity="center"
                />
            <Button
                android:background="@drawable/xiuluo"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                />
            <TextView
                android:textColor="@color/colorAccent"
                android:textSize="30sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="戰(zhàn)士:馬超"
                android:gravity="center"
                />
            <Button
                android:background="@drawable/machao"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                />
            <TextView
                android:textColor="@color/colorAccent"
                android:textSize="30sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="戰(zhàn)士:李信"
                android:gravity="center"
                />
            <Button
                android:background="@drawable/lixin"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                />
            <TextView
                android:textColor="@color/colorAccent"
                android:textSize="30sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="戰(zhàn)士:關(guān)羽"
                android:gravity="center"
                />
            <Button
                android:background="@drawable/gangyu"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                />
            <TextView
                android:textColor="@color/colorAccent"
                android:textSize="30sp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="戰(zhàn)士:楊戩"
                android:gravity="center"
                />
            <Button
                android:background="@drawable/yangjian"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

 Main2Activity.java

package com.example.dialogapplication;
 
import android.os.Bundle;
 
import androidx.appcompat.app.AppCompatActivity;
 
public class Main2Activity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }
}

到此這篇關(guān)于Android超詳細(xì)介紹自定義多選框與點(diǎn)擊按鈕跳轉(zhuǎn)界面的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Android 自定義多選框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

广河县| 旺苍县| 韶关市| 英超| 白河县| 名山县| 黑山县| 沙田区| 龙川县| 即墨市| 武城县| 浠水县| 正蓝旗| 承德市| 准格尔旗| 包头市| 灵宝市| 青冈县| 永寿县| 阳新县| 会同县| 闸北区| 嵊州市| 隆回县| 江安县| 伊宁县| 六盘水市| 泸水县| 兰西县| 象州县| 文登市| 大厂| 调兵山市| 宁远县| 宁国市| 绥化市| 公主岭市| 扶绥县| 英吉沙县| 通州区| 唐海县|