我想使用微调项目。 我希望下拉菜单的宽度和高度与按钮相同。
我该怎么做?
最后,我使用listview将其解析为这样的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 :(得分:1)
您可以使用弹出窗口。并创建自己的Spinner Popup。 下面的示例代码
27291 CRAZY ./workers/SpeedAnalysisJob.php - Wednesday, 25-Jan-17 11:29:39 UTC - Monday, 30-Jan-17 11:26:05 UTC
pop_up_window.xml
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);