2017-01-30 4 views
0

enter image description hereスピナーにスタイルを適用する

スピナーアイテムを使用したいと思っています。 ボタンの幅と高さが同じになるようにドロップダウンします。

どうすればいいですか?

は最終的に私はこのようなalertdialogにリストビューを使用して、それを解決した:私のニーズのために

public void seleccionaTemporada(View view) { 
     AlertDialog.Builder selector = new AlertDialog.Builder(SeleccionaTemporadaActivity.this); 
     selector.setTitle("Temporadas"); 

     selector.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       dialog.dismiss(); 
      } 
     }); 

     selector.setAdapter(temporadas, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       Intent intent = new Intent(getApplicationContext(), DashBoardActivity.class); 
       intent.putExtra("temporada", temporadas.getItem(which)); 
       startActivity(intent); 
      } 
     }); 
     selector.show(); 
    } 

<Button 
     android:id="@+id/btn_selecciona_temporada" 
     android:layout_width="300dp" 
     android:layout_height="200dp" 
     android:layout_alignParentStart="true" 
     android:layout_centerVertical="true" 
     android:layout_marginStart="70dp" 
     android:drawableStart="@mipmap/ic_balon" 
     android:onClick="seleccionaTemporada" 
     android:text="@string/seleccionarTemporada" 
     android:textSize="25sp" /> 

を、それは私が考える最善の解決策です。私の悪い説明を前に申し訳ありません。

+0

以下 サンプルコードあなたは何のレイアウトを使用していますか?あなたのxmlを質問に追加すると便利です。 – Phantomazi

答えて

1

ポップアップウィンドウを使用できます。独自のスピナーポップアップを作成します。

LayoutInflater inflater = (LayoutInflater)parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.pop_up_window, null); 
     RelativeLayout layout1 = holder.relativeLayout_multiChoiceDropDown; 

     pw = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true); 

     pw.setBackgroundDrawable(new BitmapDrawable()); 
     pw.setTouchable(true); 
     pw.setOutsideTouchable(true); 
     pw.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 

     pw.setTouchInterceptor(new View.OnTouchListener() 
     { 
      public boolean onTouch(View v, MotionEvent event) 
      { 
       if (event.getAction() == MotionEvent.ACTION_OUTSIDE) 
       { 
        pw.dismiss(); 
        return true; 
       } 
       return false; 
      } 
     }); 

    pw.setContentView(layout); 
    pw.showAsDropDown(layout1, -5, 0); 

    final ListView list = (ListView) layout.findViewById(R.id.dropDownList); 
    Adapter_DropDown adapter = new Adapter_DropDown(parentActivity, items); 
    list.setAdapter(adapter); 

pop_up_window.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/PopUpView" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@color/qatool_basic_info_dropdown" 
       android:orientation="vertical"> 

    <ListView 
     android:id="@+id/dropDownList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:divider="#000" 
     android:dividerHeight="0.5dp"> 
    </ListView> 

</LinearLayout> 
関連する問題