问题描述
我要实现ui结果:
但我明白了:
和资源代码是:
- 主要活动
public class MainActivity extends AppCompatActivity {
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = findViewById(R.id.et);
new Handler().postDelayed(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void run() {
SearchPopupWindow dialog = new SearchPopupWindow(MainActivity.this);
dialog.showAsDropDown(et,Gravity.CENTER_HORIZONTAL);
}
},200);
}
}
- 搜索弹出窗口
public class SearchPopupWindow extends BasePopupWindow {
public SearchPopupWindow(Context context) {
super(context);
}
@Override
public int getLayoutId() {
return R.layout.popup_layout;
}
}
- BasePopupWindow
public abstract class BasePopupWindow extends PopupWindow {
private Context mContext;
public BasePopupWindow(Context context) {
this.mContext = context;
initView();
}
public abstract int getLayoutId();
private void initView() {
LinearLayout linearLayout = new LinearLayout(mContext);
View v = LayoutInflater.from(mContext).inflate(getLayoutId(),linearLayout);
setContentView(v);
setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
setFocusable(true);
setoutsidetouchable(true);
setBackgroundDrawable(new ColorDrawable(0x00000000));
// setAnimationStyle(R.style.CustomDialogAnimation);
}
}
当用户输入一些字母时,我们的应用程序需要给出建议,例如输入 A,我们需要给 Alice。而且进展不顺利,所以我需要帮助,我想将 PopupWindow 居中水平。但是 PupupWindow 被留下了。我的设备是在 Android 9. 我该如何解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)