Android超詳細(xì)介紹自定義多選框與點(diǎn)擊按鈕跳轉(zhuǎn)界面的實(shí)現(xiàn)
總程:在avtivity_main.xml設(shè)計5個控件,btn1-5,點(diǎn)擊btn1彈出一個多選對話框,點(diǎn)擊按鈕btn1彈出一個多選框可選擇你喜歡的打野英雄,點(diǎn)擊btn2跳轉(zhuǎn)到activity_main2界面(就是圖片,不可選擇)設(shè)計思路流程:在activity_main.xml布局界面,總體在頭目錄進(jìn)行垂直排列,然后鑲嵌5個水平的線性布局(左是ImageView,右邊是Button按鈕)由于5張圖的大小在一個屏幕顯示不出來,所以添加一個ScoveView滾動,以使所有資源可以看到!
在MainActivity.java對按鈕調(diào)用其id進(jìn)行監(jiān)聽,可見btn1.set......是彈出Multi多選對話框的功能,(如果不知道對話框的知識可以去了解,就是引用其類,設(shè)置相關(guān)屬性,title,icon,message等)然后把他show()出來。btn2.set.......是引入intent(用于綁定程序組件間的綁定,就是跳轉(zhuǎn)到不同的activity.java)相關(guān)知識點(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)和錯誤還望大佬和給位博主指出,讓我知道錯誤點(diǎn),如果對你有所幫助就點(diǎn)個贊鼓勵一下把!
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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android使用kotlin實(shí)現(xiàn)多行文本上下滾動播放
這篇文章主要為大家詳細(xì)介紹了Android使用kotlin實(shí)現(xiàn)多行文本的上下滾動播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-01-01
Android ListView與ScrollView沖突的解決方法總結(jié)
這篇文章主要介紹了Android ListView與ScrollView沖突的解決方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-04-04
Android png透明圖片轉(zhuǎn)jpg時背景變黑的解決方法
這篇文章主要介紹了Android png透明圖片轉(zhuǎn)jpg時背景變黑的解決方法,需要的朋友可以參考下2017-12-12
Android拖拽助手ViewDragHelper的創(chuàng)建與使用實(shí)例
ViewDragHelper是針對 ViewGroup 中的拖拽和重新定位 views 操作時提供了一系列非常有用的方法和狀態(tài)追蹤,下面這篇文章主要給大家介紹了關(guān)于Android拖拽助手ViewDragHelper的創(chuàng)建與使用的相關(guān)資料,需要的朋友可以參考下2022-05-05
ubuntu環(huán)境下反編譯android apk的方法
今天小編就為大家分享一篇關(guān)于ubuntu環(huán)境下反編譯android apk的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03
詳解Android開發(fā)錄音和播放音頻的步驟(動態(tài)獲取權(quán)限)
這篇文章主要介紹了詳解Android開發(fā)錄音和播放音頻的步驟(動態(tài)獲取權(quán)限),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Android自定義View實(shí)現(xiàn)水波紋效果
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)水波紋效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08

