定制的Android微调 [英] Custom Android Spinner
问题描述
我寻找到创建自定义的项目选择又名微调我的应用程序。我想是这样你可以在应用程序松弛看到当你点击你所在的房间。
I'm looking into creating a custom project selector aka spinner for my App. I want something like what you can see in the Slack app when you click on the room you're in.
我觉得这是一个很好的老对话模式微调,但我不知道我是怎么做到以下几点:
I think this is a Spinner with a good old dialog mode but I'm not sure how I do the following:
1)删除背景色(在对话外)结果
2)在顶部锚的对话框而不是在屏幕的中心。
1) Remove the background tint (outside of the dialog)
2) Anchor the dialog at the top rather than the centre of the screen.
这是例子:
推荐答案
原来这就是我结束了,如果有人面临着类似的问题,这样做的:
So this is what I ended up doing if anyone faces a similar problem:
spinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) {
return true;
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//code goes here
}
});
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.dimAmount=0.0f;
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = 100; //x position
wmlp.y = 100; //y position
dialog.getWindow().setAttributes(wmlp);
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.show();
return true;
}
});
答案是基于<一个href=\"http://stackoverflow.com/questions/5469005/show-alertdialog-in-any-position-of-the-screen\">Show AlertDialog在屏幕中的任何位置,从而非常感谢原作者!
The answer is based on Show AlertDialog in any position of the screen so thanks a lot to the original author!
这篇关于定制的Android微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!