标签: android-popupwindow

自定义弹出菜单

您好我必须创建一个PopUp菜单,我知道如何做到这一点.

这是我创建默认PopUp菜单的代码..

popup_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/item"
    android:showAsAction="ifRoom|withText"
    android:title="item1"
    android:visible="true"/>
<item
    android:id="@+id/item2"
    android:showAsAction="ifRoom|withText"
    android:title="item2"
    android:visible="true"/>
<item
    android:id="@+id/item3"
    android:showAsAction="ifRoom|withText"
    android:title="item3"
    android:visible="true"/>
Run Code Online (Sandbox Code Playgroud)

PopUpMenu_Activity.java

findViewById(R.id.btn_click).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            PopupMenu popupMenu = new PopupMenu(PopMenuActivity.this, view);
            popupMenu.setOnMenuItemClickListener(PopMenuActivity.this);
            popupMenu.inflate(R.menu.popup_menu);
            popupMenu.show();
        }
    });
Run Code Online (Sandbox Code Playgroud)

public boolean onMenuItemClick(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.item1:
        Toast.makeText(this, "item1 clicked", Toast.LENGTH_SHORT).show();
        return true;
    case R.id.item2:
        Toast.makeText(this, "item2 clicked", Toast.LENGTH_SHORT).show();
        return true;
    case R.id.item3:
        Toast.makeText(this, "item3 clicked", Toast.LENGTH_SHORT).show();
        return true;
    default:
        return false;
    }

} …
Run Code Online (Sandbox Code Playgroud)

android android-menu android-contextmenu android-popupwindow

5
推荐指数
1
解决办法
5440
查看次数

Android popupWindow,无法在弹出窗口中获取元素

我有一个问题,Button从我的内部抓住我的s和其他元素PopupWindow,使用debugger它只是报告回来null

private void initiatePopupWindow() 
        { 
            try 
                { 
                    // We need to get the instance of the LayoutInflater 
                    LayoutInflater inflater = (LayoutInflater) LoginActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                    View layout = inflater.inflate(R.layout.activity_register,(ViewGroup)

                    findViewById(R.id.popup_element)); 
                    pwindo = new PopupWindow(layout, 600, 900, true);
                    pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

                    btnReg = (Button) findViewById(R.id.btnReg);
                    inputName = (EditText) findViewById(R.id.name);
                    inputDOB = (DatePicker) findViewById(R.id.dob);
                    String name = inputName.getText().toString();

                    btnReg.setOnClickListener(new View.OnClickListener()
                    {
                        @Override
                        public void onClick(View v)
                        {


                            if (  ( !inputName.getText().toString().equals("")) &&
                                    ( getAge(inputDOB.getDayOfMonth(), inputDOB.getMonth(), inputDOB.getYear()) …
Run Code Online (Sandbox Code Playgroud)

android android-popupwindow

4
推荐指数
1
解决办法
2917
查看次数

选择textview时如何显示弹出窗口而不是CAB?

我正在制作一个阅读应用程序,它有一个全屏活动.
当用户选择文本的一部分时,会contextual action bar出现复制选项.这是默认行为.但是此操作栏会阻止其下的文本,因此用户无法选择它.

我想显示一个如下所示的弹出窗口.
在此输入图像描述

我试图返回falseonCreateActionMode,但是当我这样做,我不能选择文本两种.

我想知道是否有一种标准的方法来实现这一点,因为许多阅读应用程序都使用这种设计.

android textview android-actionmode android-popupwindow

4
推荐指数
1
解决办法
897
查看次数

PopupWindow 被截断至屏幕底部

PopupWindow 会很好地膨胀,直到它接近屏幕底部为止,它被切断。有人知道当它朝向屏幕底部时如何向上充气吗?

在此输入图像描述

public SelectBucketMenu(Context context) {
        super(context);
        this.mContext = context;

        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setOutsideTouchable(true);
        setFocusable(true);
        //Need set windowlayout for API 19 otherwise window won't appear
        setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        setupView();
    }

    private void setupView(){
        View view = LayoutInflater.from(mContext)
                .inflate(R.layout.popupmenu_selectbucket, null);
        ButterKnife.bind(this, view);
        setContentView(view);
    }
Run Code Online (Sandbox Code Playgroud)

有人知道为什么吗?

android android-popupwindow

4
推荐指数
1
解决办法
1760
查看次数

如何为列表弹出窗口设置圆角背景?

我有一个具有锐利矩形背景的菜单。我已经尝试了很多,但无法将其更改为圆形背景。 弹出菜单.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#1F2026"
    android:orientation="horizontal"
    >

<TextView
    android:id="@+id/details"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:fontFamily="@font/quicksand_regular"
    android:text="@string/add_to_favourite"
    android:textColor="@color/icon_color_dark" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

上面给出的是我的弹出菜单 xml。

 public static void showAlbumPopupOptions(final Activity activity, ImageView listMore,
                                         final Song song, String songId, int playingState) {

    final boolean isLogged = AppController.getBooleanPreference(Constants.LOGGED_IN, false);

    String[] listItems;

    listItems = activity.getResources().getStringArray(R.array.popup_menu_add_album);

    ArrayAdapter<String> mPopupAdapter = new ArrayAdapter<>(activity, R.layout.popup_menu, R
            .id.details, listItems);

    final ListPopupWindow albumPopup = new ListPopupWindow(activity);
    albumPopup.setContentWidth(Utils.measureContentWidth(mPopupAdapter, activity));

    albumPopup.setAdapter(mPopupAdapter);
    albumPopup.setHeight(ListPopupWindow.WRAP_CONTENT);
    albumPopup.setAnchorView(listMore);
    albumPopup.setModal(true);
    albumPopup.setDropDownGravity(Gravity.END);
    final LoadingProgressDialog loadingProgressDialog = new LoadingProgressDialog(activity, R
            .style
            .DialogThemeProgress, false); …
Run Code Online (Sandbox Code Playgroud)

android popupmenu android-styles android-popupwindow material-components-android

4
推荐指数
1
解决办法
7816
查看次数

PopupWindow显示时未调用onBackPressed

嘿伙计们,

所以目前我正在使用PopupWindow来显示应用程序内浏览器.然而,当按下后退按钮时它什么都不做.我在另一个片段中使用PopupWindow,然后我使用一个语句在我的FragmentActivity中设置PopupWindow,然后当我按下我的后退按钮时,它应该检查PopupWindow是否被设置并且不关闭它.但它甚至没有通过onBackPressed运行.

片段中的PopupWindow:

- >是指出确保FragmentActivity获取PopupWindow的行.

// Use webview for icons and website link.
public void inAppBrowser(String url){
    mCursor.moveToFirst();
    // Inflate View
    LayoutInflater layoutInflater = (LayoutInflater) ((MainActivity) MainActivity.getContext()).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View inflatedView = layoutInflater.inflate(R.layout.browser_window, null, false);

    // Control View Childs.
    LinearLayout header = (LinearLayout) inflatedView.findViewById(R.id.filter_header);
    header.setBackgroundColor(Color.parseColor(color));
    Button cancel = (Button) inflatedView.findViewById(R.id.cancel);
    Button done = (Button) inflatedView.findViewById(R.id.done);

    // Set PopupWindow position.
    Display display = ((MainActivity) MainActivity.getContext()).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);

    // Control PopupWindow.
    final PopupWindow popWindow = new PopupWindow(inflatedView, size.x, size.y, …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-popupwindow

3
推荐指数
1
解决办法
2429
查看次数

Android M ClassCastException:FrameLayout $ LayoutParams无法强制转换为WindowManager $ LayoutParams

这段代码工作似乎在android api 16 - 22中工作但在api 23中不起作用.我只是试图在其中显示一个带有选项的popupwindow并将背景调暗到popupwindow下面:

                WindowPopUp windowPopUp =
                        new WindowPopUp(mContext, mPlaces.get(position), position, fromSearch);
                windowPopUp.showAtLocation(v, Gravity.CENTER, 0, 0);
                View parent = (View) windowPopUp.getContentView().getParent();
                //dim the window in the background
                WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
                WindowManager.LayoutParams p = (WindowManager.LayoutParams) parent.getLayoutParams();
                p.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                p.dimAmount = 0.4f;
                wm.updateViewLayout(parent, p);
Run Code Online (Sandbox Code Playgroud)

运行此代码会导致错误:

                03-18 21:55:19.674 8814-8814/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             Process: com.myapp, PID: 8814
                                             java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
                                                 at com.bemyapp.adapter.OuterPlaceAdapter$5.onLongClick(OuterPlaceAdapter.java:400)
                                                 at android.view.View.performLongClick(View.java:5237)
                                                 at android.view.View$CheckForLongPress.run(View.java:21121)
                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                 at android.os.Looper.loop(Looper.java:148)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) …
Run Code Online (Sandbox Code Playgroud)

android layoutparams android-popupwindow android-6.0-marshmallow

3
推荐指数
1
解决办法
1615
查看次数

Android Nougat 7.1.1 showAtLocation(...) 重力不起作用

这与这个问题相关: Android Nougat PopupWindow showAsDropDown(...) Gravity notworking

但是,当我应用此修复程序时:

if (android.os.Build.VERSION.SDK_INT >=24) {
    int[] a = new int[2];
    anchorView.getLocationInWindow(a);
    popUp.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0 , a[1]+anchorView.getHeight());
} else{
    popUp.showAsDropDown(anchorView);
}
Run Code Online (Sandbox Code Playgroud)

它不适用于 Android Nougat 7.1.1。特别是在 Google Pixel 和 Nexus 6p 设备上。

有人解决这个问题了吗?请分享。 https://code.google.com/p/android/issues/detail?id=231487

android android-popupwindow android-7.1-nougat

3
推荐指数
1
解决办法
3260
查看次数

如何关闭Android中的弹出窗口?

我有一个弹出窗口,当单击活动中的按钮时会弹出该窗口。该对话框覆盖整个屏幕,仅包含三个按钮。如果单击按钮,则它们会相应地起作用。但是,如果用户触摸按钮以外的弹出窗口中的任何位置,我希望弹出窗口关闭。我尝试了以下代码。

popupWindow.setOutsideTouchable(true);
popupWindow.showAtLocation(layout, Gravity.FILL, 0, 0);

popupWindow.setTouchInterceptor(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            popupWindow.dismiss();
            return true;
        }
        return false;
    }
});
Run Code Online (Sandbox Code Playgroud)

但它没有用。我还设置了这个:

popupWindow.setFocusable(true);

popupWindow.setTouchable(true);
Run Code Online (Sandbox Code Playgroud)

我的弹出式布局如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_element"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="10px">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:padding="10dp">

        <ImageButton
            android:id="@+id/voiceCall"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center|center_horizontal"
            android:background="@drawable/round_button"
            android:padding="15dp"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_call_black_24dp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Voice Call"
            android:textColor="#ffffff"
            android:textSize="20dp" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如果我单击此弹出窗口中除这两个按钮之外的任何位置,我希望它被关闭。没有什么对我有用。谁能建议我如何做到这一点?另外,如果单击设备后退按钮,我希望弹出窗口消失。

android view onclick back android-popupwindow

3
推荐指数
1
解决办法
6774
查看次数

在 PopupWindow 中设置带有 WebView 的 setBuiltInZoomControls

我有一个 PopupWindow,它在按下按钮时显示一个 WebView。如果 setBuiltInZoomControls 设置为false,则 WebView 按预期显示页面。但是,如果 setBuiltInZoomControls 设置为true,则与 WebView(滚动、捏合缩放)的任何交互都会导致错误。

这是Java代码:

  mHelpButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = inflater.inflate(R.layout.help_pop, null);
            int width = WindowManager.LayoutParams.MATCH_PARENT;
            int height = WindowManager.LayoutParams.WRAP_CONTENT;
            final PopupWindow popupWindow = new PopupWindow(popupView, 1, 1, true);
            popupWindow.setWindowLayoutMode(width,height);
            popupWindow.setOutsideTouchable(true);
            popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(), ""));
            TextView helpText = (TextView) popupView.findViewById(R.id.help_text);
            WebView webView = (WebView)popupView.findViewById(R.id.app_question_help_web_view);
            if (!mQuestion.casiHelpText.contains("http://") && !mQuestion.casiHelpText.contains("<")) {
                helpText.setText(mQuestion.casiHelpText);
                popupWindow.showAsDropDown(mHelpButton);
            } else if (mQuestion.casiHelpText.contains("http://") && !mQuestion.casiHelpText.contains("<")) {
                if …
Run Code Online (Sandbox Code Playgroud)

android zooming webview android-popupwindow

2
推荐指数
1
解决办法
2115
查看次数