欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

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,在其可設置要執(zhí)行的相關功能,也可不進行設置(以實際情況功能而定)在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)士:關羽"
                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);
    }
}

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

相關文章

  • Android使用kotlin實現(xiàn)多行文本上下滾動播放

    Android使用kotlin實現(xiàn)多行文本上下滾動播放

    這篇文章主要為大家詳細介紹了Android使用kotlin實現(xiàn)多行文本的上下滾動播放,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Android ListView與ScrollView沖突的解決方法總結

    Android ListView與ScrollView沖突的解決方法總結

    這篇文章主要介紹了Android ListView與ScrollView沖突的解決方法總結的相關資料,需要的朋友可以參考下
    2017-04-04
  • Android png透明圖片轉jpg時背景變黑的解決方法

    Android png透明圖片轉jpg時背景變黑的解決方法

    這篇文章主要介紹了Android png透明圖片轉jpg時背景變黑的解決方法,需要的朋友可以參考下
    2017-12-12
  • Android拖拽助手ViewDragHelper的創(chuàng)建與使用實例

    Android拖拽助手ViewDragHelper的創(chuàng)建與使用實例

    ViewDragHelper是針對 ViewGroup 中的拖拽和重新定位 views 操作時提供了一系列非常有用的方法和狀態(tài)追蹤,下面這篇文章主要給大家介紹了關于Android拖拽助手ViewDragHelper的創(chuàng)建與使用的相關資料,需要的朋友可以參考下
    2022-05-05
  • ubuntu環(huán)境下反編譯android apk的方法

    ubuntu環(huán)境下反編譯android apk的方法

    今天小編就為大家分享一篇關于ubuntu環(huán)境下反編譯android apk的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Android控件系列之CheckBox使用介紹

    Android控件系列之CheckBox使用介紹

    CheckBox和Button一樣,也是一種古老的控件,它的優(yōu)點在于,不用用戶去填寫具體的信息,只需輕輕點擊,缺點在于只有“是”和“否”兩種情況,但我們往往利用它的這個特性,來獲取用戶的一些信息
    2012-11-11
  • 詳解Android開發(fā)錄音和播放音頻的步驟(動態(tài)獲取權限)

    詳解Android開發(fā)錄音和播放音頻的步驟(動態(tài)獲取權限)

    這篇文章主要介紹了詳解Android開發(fā)錄音和播放音頻的步驟(動態(tài)獲取權限),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • Android手機鬧鐘用法實例

    Android手機鬧鐘用法實例

    這篇文章主要介紹了Android手機鬧鐘用法,以實例形式較為詳細的分析了Android實現(xiàn)鬧鐘功能的頁面布局及具體功能相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • Android自定義View實現(xiàn)水波紋效果

    Android自定義View實現(xiàn)水波紋效果

    這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)水波紋效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android相機Camera基礎知識

    Android相機Camera基礎知識

    這篇文章主要為大家詳細介紹了Android相機Camera基礎知識,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01

最新評論