Android超詳細介紹自定義多選框與點擊按鈕跳轉(zhuǎn)界面的實現(xiàn)
總程:在avtivity_main.xml設(shè)計5個控件,btn1-5,點擊btn1彈出一個多選對話框,點擊按鈕btn1彈出一個多選框可選擇你喜歡的打野英雄,點擊btn2跳轉(zhuǎn)到activity_main2界面(就是圖片,不可選擇)設(shè)計思路流程:在activity_main.xml布局界面,總體在頭目錄進行垂直排列,然后鑲嵌5個水平的線性布局(左是ImageView,右邊是Button按鈕)由于5張圖的大小在一個屏幕顯示不出來,所以添加一個ScoveView滾動,以使所有資源可以看到!
在MainActivity.java對按鈕調(diào)用其id進行監(jiān)聽,可見btn1.set......是彈出Multi多選對話框的功能,(如果不知道對話框的知識可以去了解,就是引用其類,設(shè)置相關(guān)屬性,title,icon,message等)然后把他show()出來。btn2.set.......是引入intent(用于綁定程序組件間的綁定,就是跳轉(zhuǎn)到不同的activity.java)相關(guā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)功能,也可不進行設(shè)置(以實際情況功能而定)在activity_main2.xml布局你喜歡的界面,然后點擊按鈕2即可彈出,PS:一定要在迷你fest.xmlactivity,如果有不當和錯誤還望大佬和給位博主指出,讓我知道錯誤點,如果對你有所幫助就點個贊鼓勵一下把!
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="點擊選擇你喜歡的王者榮耀打野英雄(文字形式)"
/>
</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="點擊選擇你喜歡的王者榮耀上單英雄"
/>
</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="點擊選擇你喜歡的王者榮耀射手英雄"
/>
</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="點擊選擇你喜歡的王者榮耀中路英雄"
/>
</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="點擊選擇你喜歡的王者榮耀輔助英雄"
/>
</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超詳細介紹自定義多選框與點擊按鈕跳轉(zhuǎn)界面的實現(xiàn)的文章就介紹到這了,更多相關(guān)Android 自定義多選框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android開發(fā)之獲取SD卡及手機ROM容量的方法
這篇文章主要介紹了Android開發(fā)之獲取SD卡及手機ROM容量的方法,結(jié)合實例形式分析了Android針對SD卡的讀取及屬性操作相關(guān)技巧,需要的朋友可以參考下2016-04-04
Android?數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析
這篇文章主要為大家介紹了Android?數(shù)據(jù)結(jié)構(gòu)全面總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12
Android開發(fā)筆記之Android中數(shù)據(jù)的存儲方式(一)
這篇文章主要介紹了Android開發(fā)筆記之Android中數(shù)據(jù)的存儲方式(一) 的相關(guān)資料,需要的朋友可以參考下2016-01-01
RecyclerView無限循環(huán)效果實現(xiàn)及示例解析
這篇文章主要為大家介紹了RecyclerView無限循環(huán)效果實現(xiàn)及示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03
Android實現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器
這篇文章主要介紹了Android實現(xiàn)仿網(wǎng)易新聞的頂部導(dǎo)航指示器的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08
在Android中通過Intent使用Bundle傳遞對象的使用方法
這篇文章主要介紹了在Android中通過Intent使用Bundle傳遞對象的使用方法,詳細介紹Intent使用Bundle傳遞對象的方法。有需要的可以了解一下。2016-11-11
C#中利用正則表達式將人民幣金額轉(zhuǎn)換為大寫漢字
這篇文章主要介紹了C#中利用正則表達式將人民幣金額轉(zhuǎn)換為大寫漢字的方法,需要的朋友可以參考下2016-02-02

