溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

自定義Spinner---利用TextView以及Dialog組合

發(fā)布時(shí)間:2020-06-24 11:40:22 來(lái)源:網(wǎng)絡(luò) 閱讀:1293 作者:鷺島猥瑣男 欄目:移動(dòng)開(kāi)發(fā)

MainActivity:



package com.example.myspinner_bytextview;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author 鷺島猥瑣男
 *
 */
public class MainActivity extends Activity
{

    private TextView tv_show;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        View sex = findViewById(R.id.sex);
        tv_show = (TextView) findViewById(R.id.tv_show);
        sex.setOnClickListener(new OnClickListener()
        {
           
            @Override
            public void onClick(View v)
            {
                AlertDialog.Builder builder;
                final AlertDialog dialog;
                View view = getLayoutInflater().inflate(R.layout.myspinner, null);
                builder=new AlertDialog.Builder(MainActivity.this);
                dialog=builder.create();
                dialog.setView(view, 0, 0, 0, 0);
                dialog.show();
                View sex_man = view.findViewById(R.id.sex_man);
                View woman = view.findViewById(R.id.woman);
                View shemale = view.findViewById(R.id.shemale);
                sex_man.setOnClickListener(new OnClickListener()
                {
                   
                    @Override
                    public void onClick(View v)
                    {
                        tv_show.setText("男性");
                        Toast.makeText(MainActivity.this, "性別:男性", Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                       
                    }
                });
               
                woman.setOnClickListener(new OnClickListener()
                {
                   
                    @Override
                    public void onClick(View v)
                    {
                        tv_show.setText("女性");
                        Toast.makeText(MainActivity.this, "性別:男性", Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                       
                    }
                });
               
                shemale.setOnClickListener(new OnClickListener()
                {
                   
                    @Override
                    public void onClick(View v)
                    {
                        tv_show.setText("人妖");
                        Toast.makeText(MainActivity.this, "性別:男性", Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                       
                    }
                });
               
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}



activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <RelativeLayout
        android:id="@+id/sex"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/sex_selector"
        android:layout_marginTop="60dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="30dp"
            android:text="性別"
            android:textSize="20sp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/tv_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:text="男性"
             android:textSize="20sp"
             android:textColor="#646464"
            android:layout_toLeftOf="@+id/p_w_picpathView1"
            android:layout_centerVertical="true"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <ImageView
            android:id="@+id/p_w_picpathView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="30dp"
            android:contentDescription="@string/app_name"
            android:src="@drawable/mydown" />

    </RelativeLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/sex"
        android:background="#dcdcdc"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/sex"
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>



mydialog.xml:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc" />

    <RelativeLayout
        android:id="@+id/sex_man"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/textView1"
         android:background="@drawable/sex_selector"
        android:layout_centerHorizontal="true" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="男性"
            android:textSize="20sp"
          
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/sex_man"
        android:background="#dcdcdc"
        android:layout_centerHorizontal="true"
         />

    <RelativeLayout
        android:id="@+id/woman"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/textView3"
         android:background="@drawable/sex_selector"
        android:layout_centerHorizontal="true" >

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="女性"
            android:textSize="20sp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/woman"
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc"
         />

    <RelativeLayout
        android:id="@+id/shemale"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/textView5"
        android:background="@drawable/sex_selector"
        android:layout_centerHorizontal="true" >

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="人妖"
            android:textSize="20sp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

    <TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#dcdcdc"
        android:layout_below="@+id/shemale"
        android:layout_centerHorizontal="true"
         />

</RelativeLayout>



自定義Spinner---利用TextView以及Dialog組合

自定義Spinner---利用TextView以及Dialog組合

自定義Spinner---利用TextView以及Dialog組合


DownLoad:http://download.csdn.net/detail/zzw0221/7530723


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI