I want to implement ui result:
but I get:
and resource code is:
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,0,0, Gravity.CENTER_HORIZONTAL);
           }
       }, 200);
   }
}
public class SearchPopupWindow extends BasePopupWindow {
    public SearchPopupWindow(Context context) {
        super(context);
    }
    @Override
    public int getLayoutId() {
        return R.layout.popup_layout;
    }
}
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);
    }
}
Our App neet to give advices when User input some letter,like input A ,we need give Alice.And It's not going well,so I need help,I want to PopupWindow center horizental.But PupupWindow is left.My device is in Android 9.How can I solve this?
User contributions licensed under CC BY-SA 3.0