标签: android-popupwindow

Android弹出窗口没有填充屏幕大小?

我正在尝试制作一个简单的弹出窗口.但是每次我制作一个,它最终都会变得非常小......而不是我想要它的长度.这是弹出窗口的样子: 在此输入图像描述

这是弹出窗口的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_element"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#444444"
    android:padding="10px"
    android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Transfering data"
        android:textColor="@color/white"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="Status"
        android:textColor="@color/white"/>

    <TextView android:id="@+id/server_status_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Awaiting answer..."
        android:paddingLeft="10sp"
        android:textColor="@color/white"/>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:gravity="center_horizontal|bottom">

        <Button android:id="@+id/end_data_send_button"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:drawablePadding="3sp"
            android:layout_centerHorizontal="true"
            android:text="Cancel" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的java代码:

private PopupWindow pw;
        private void bindActivity() {

            fabButton = (ImageButton) findViewById(R.id.activity_profileView_FAB);
            fabButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    initiatePopupWindow();
                }
            });


        }
     private void initiatePopupWindow() {
            try …
Run Code Online (Sandbox Code Playgroud)

android popupwindow android-popupwindow

15
推荐指数
2
解决办法
7万
查看次数

通过后退按钮关闭弹出窗口

我想通过单击弹出窗口外部或后退按钮来关闭弹出窗口,但是当单击后退按钮我的应用程序退出时,而不是退出应用程序我想要关闭弹出窗口.

这是我的代码,

ivmainmenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            LayoutInflater layoutInflater 
             = (LayoutInflater)getBaseContext()
              .getSystemService(LAYOUT_INFLATER_SERVICE);  
            View popupView = layoutInflater.inflate(R.layout.popupwindow, null);  
          final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.FILL_PARENT,
                  LayoutParams.WRAP_CONTENT);  
                popupWindow.showAsDropDown(ivmainmenu, 0,14);
                popupView.setPadding(0, 0, 0, 10);
                popupWindow.showAsDropDown(ivmainmenu);

                popupWindow.setBackgroundDrawable(new BitmapDrawable());
                popupWindow.setOutsideTouchable(false);

                TextView tvpopupwork = (TextView)popupView.findViewById(R.id.tvpopupwork);
                TextView tvpopupabout = (TextView)popupView.findViewById(R.id.tvpopupabout);
                TextView tvpopupservices = (TextView)popupView.findViewById(R.id.tvpopupservices);
                TextView tvpopupcontact = (TextView)popupView.findViewById(R.id.tvpopupcontact);

                Typeface typeFace2 =  Typeface.createFromAsset(getAssets(),"fonts/arboriaboldregular.ttf");
                tvpopupwork.setTypeface(typeFace2);
                tvpopupabout.setTypeface(typeFace2);
                tvpopupservices.setTypeface(typeFace2);
                tvpopupcontact.setTypeface(typeFace2);

                tvpopupwork.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method …
Run Code Online (Sandbox Code Playgroud)

android android-popupwindow

12
推荐指数
2
解决办法
2万
查看次数

在Android中更改背景popupMenu

我试图改变popupmenu的背景,但我的实现不起作用.

这是我的代码:

<style name="MyHoloLight" parent="android:Theme.Holo.Light">
    <item name="android:popupMenuStyle">@style/popupMenuStyle</item>
</style>
<style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
    <item name="android:popupBackground">@color/bgPopumMenu</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在AndroidManifest.xml中应用

<application
        android:hardwareAccelerated="true"
        android:label="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/MyHoloLight">
Run Code Online (Sandbox Code Playgroud)

android android-theme android-styles android-popupwindow

11
推荐指数
3
解决办法
2万
查看次数

PopupWindow onitemclick中的Android Listview无法在某些设备上运行

我的ListView在PopupWindow中.

当我显示PopupWindow并点击设备ASUS K00z fonepad中的Listview行时非常好.

但在HTC Z715e不工作(onitem点击事件未被解雇)

这是我的listview项目布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ln_testpopitemcon"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="52dp"
    android:background="#3b8ed4"
    android:descendantFocusability="blocksDescendants">

<ImageView
    android:id="@+id/img_testiconmenu"
    android:layout_margin="10dp"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:src="@drawable/radio_selected"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

    <TextView
        android:id="@+id/tv_testtitlemenu"
        android:gravity="left|center_vertical"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的弹出式布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ln_testpopocontainer"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:paddingBottom="2dp"
        android:id="@+id/lv_testpop"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:choiceMode="singleChoice"
        android:dividerHeight="2dp"
        android:background="#00000000"
        android:orientation="vertical"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的适配器

public class testmenuadapter extends BaseAdapter{
    private Context context;
    private ArrayList<MenuInfo> MenuList;
    private LayoutInflater Layf;

    public testmenuadapter(Context context, ArrayList<MenuInfo> menuList){
        this.context = context;
        this.MenuList = menuList;
        this.Layf = …
Run Code Online (Sandbox Code Playgroud)

android android-listview onitemclicklistener android-popupwindow

11
推荐指数
1
解决办法
5314
查看次数

PopupWindow在Android API 28的自定义键盘上被剪辑

我做了一个自定义键盘.当您长按一个键时,会PopupWindow在键上方显示一些额外的选项.问题是在API 28中,此弹出窗口被剪裁(甚至完全隐藏在顶行).

在此输入图像描述

我已经解决了这个问题API <28

popupWindow.setClippingEnabled(false);
Run Code Online (Sandbox Code Playgroud)

但是,对于API 28,问题又回来了.这是更多的代码:

private void layoutAndShowPopupWindow(Key key, int xPosition) {
    popupWindow = new PopupWindow(popupView,
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    popupWindow.setClippingEnabled(false);
    int location[] = new int[2];
    key.getLocationInWindow(location);
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    popupView.measure(measureSpec, measureSpec);
    int popupWidth = popupView.getMeasuredWidth();
    int spaceAboveKey = key.getHeight() / 4;
    int x = xPosition - popupWidth / popupView.getChildCount() / 2;
    int screenWidth = getScreenWidth();
    if (x < 0) {
        x = 0;
    } else if (x + popupWidth > screenWidth) {
        x = …
Run Code Online (Sandbox Code Playgroud)

android android-popupwindow custom-keyboard

11
推荐指数
1
解决办法
990
查看次数

将 ComposeView 添加到 PopupWindow 的 contentView 崩溃

我试图PopupWindow从 a显示 a Fragment,然后将 a 添加ComposableView到 Popup contentView,但它崩溃了,因为ViewTreeLifecycleOwner找不到PopupDecorView$PopupDecorView

我尝试过的事情:

  • 使用PopupWindowCompat显示弹出窗口。
  • Fragment(1.3.4 和 1.4.0-alpha1)的多个库版本。
  • Activity我使用的版本是:1.3.0-alpha08。
  • contentView手动设置和的生命周期所有者ComposeView

来电:

添加:ComposeViewcontentView

 contentWindow.contentView.addView(
                AdaptiveCardistRender.adaptiveCardistResponseView(
                    contentWindow.contentView.context,
                    response
                )
            )
Run Code Online (Sandbox Code Playgroud)

显示弹出窗口:

PopupWindowCompat.showAsDropDown(
                popupWindow,
                anchor,
                0,
                startVerticalOffset,
                Gravity.NO_GRAVITY
            )
Run Code Online (Sandbox Code Playgroud)

设置生命周期PopupWindow

class ExtensionsPopupWindow(
    val contentView: ScrollView,
    width: Int,
    height: Int,
    lifecycleOwner: LifecycleOwner,
    savedStateRegistryOwner: SavedStateRegistryOwner,
) : PopupWindow(contentView, width, height, true) {

    init {
        ViewTreeLifecycleOwner.set(contentView, lifecycleOwner)
        ViewTreeSavedStateRegistryOwner.set(contentView, savedStateRegistryOwner) …
Run Code Online (Sandbox Code Playgroud)

android popupwindow android-lifecycle android-popupwindow android-jetpack-compose

10
推荐指数
1
解决办法
1642
查看次数

PopupWindow不响应拖放事件

我的应用程序中有一个菜单图标.当我拖放一些东西时,它会显示一个弹出窗口.我需要延伸我的拖延PopupWindow.

我这样做如下.

创建了一个PopupWindow,如图所示

View popupView = View.inflate(anchorView.getContext(), R.layout.layout_popup, null);

PopupWindow popUpWindow = new PopupWindow(popupView, WindowManager.LayoutParams.WRAP_CONTENT,
                                                  WindowManager.LayoutParams.WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)

并如图所示设置dragListener

popupView.setOnDragListener(new OnDragListener() {
            @Override
            public boolean onDrag(View view, DragEvent dragEvent) {



                    switch (dragEvent.getAction()) {
                    case DragEvent.ACTION_DRAG_STARTED:
                        Log.d("Drag", "ACTION_DRAG_STARTED");
                        break;
                    case DragEvent.ACTION_DRAG_ENDED:
                        Log.d("Drag", "ACTION_DRAG_ENDED");
                        break;
                    case DragEvent.ACTION_DRAG_ENTERED:
                        Log.d("Drag", "ACTION_DRAG_ENTERED");
                        break;
                    case DragEvent.ACTION_DRAG_EXITED:
                        Log.d("Drag", "ACTION_DRAG_EXITED");
                        break;
                    case DragEvent.ACTION_DROP:
                        Log.d("Drag", "ACTION_DROP");
                        break;
                    default:
                        break;
                    }

                return true;
            }
        });
Run Code Online (Sandbox Code Playgroud)

下面的视频显示了我想要实现的目标.

在此输入图像描述

但是popupView没有响应任何拖动事件.我也尝试过使用它DialogFragment,但它也没有帮助.任何帮助表示赞赏.

提前致谢.

android drag-and-drop android-popupwindow

8
推荐指数
0
解决办法
352
查看次数

Android PopupWindow:白色背景但保留阴影?

如何在Android中使用白色背景设置我的PopupWindow样式,但仍保留阴影?我想创建类似[this] [1]的东西:

目的

默认情况下,我的PopupWindow背景较暗.所以我将弹出窗口的内容设置为白色背景,这样就可以了:

白色内容背景

它有一个阴影,但仍然有黑色的"边框",这实际上只是弹出窗口背景的未覆盖部分.

因此,我想和弹出窗口背景设置为白色,"popupWindow.setBackgroundDrawable(新ColorDrawable(Color.WHITE))"这将导致:

它提供了正确的背景颜色,但也消除了阴影.

那么有没有任何简单的方法来保持阴影,但将背景设置为白色.还有什么我应该用而不是PopupWindow来创造我想要的东西吗?或者我必须使用9补丁或什么?

android android-popupwindow

7
推荐指数
1
解决办法
5038
查看次数

PopupWindow背景有时变得透明和紫色

这是我创建一个PopupWindow:

private static PopupWindow createPopup(FragmentActivity activity, View view)
{
    PopupWindow popup = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
    popup.setOutsideTouchable(true);
    popup.setFocusable(true);
    popup.setBackgroundDrawable(new ColorDrawable(Tools.getThemeReference(activity, R.attr.main_background_color)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        popup.setElevation(Tools.convertDpToPixel(8, activity));
    PopupWindowCompat.setOverlapAnchor(popup, true);

    return popup;
}
Run Code Online (Sandbox Code Playgroud)

main_background_color是纯色,白色或黑色,取决于主题.有时发生以下情况

在此输入图像描述

我怎么能避免这个?它只发生在带有android 6 SOMETIMES的模拟器中......例如,通常情况下,PopupWindow背景按预期运行...

编辑

另外,这是我的getThemeReference方法:

public static int getThemeReference(Context context, int attribute)
{
    TypedValue typeValue = new TypedValue();
    context.getTheme().resolveAttribute(attribute, typeValue, false);
    if (typeValue.type == TypedValue.TYPE_REFERENCE)
    {
        int ref = typeValue.data;
        return ref;
    }
    else
    {
        return -1;
    }
} …
Run Code Online (Sandbox Code Playgroud)

android popupwindow android-popupwindow

7
推荐指数
1
解决办法
584
查看次数

如何用list popupwindow替换我的popupmenu代码?

目前,我正在以编程方式创建一个弹出菜单,其中显示了一个楼层列表和一个标题.但是,更改标题的背景颜色并为标题添加关闭按钮变成了一场噩梦.

我想用列表弹出窗口替换这个弹出菜单,这样我就可以添加一个带有背景属性的XML文件,其中黑色作为背景,右侧是关闭按钮,菜单中的项目是白色背景.有没有办法用列表弹出窗口实现这个目的?这是我的代码:

private void floorMenu(ImageView btnFloorMenu){
    MapData data = new MapDao(MyPlugin.mapId);
    final List<Floor> flList = dao.getFloors();
    // set popupMenu
    final PopupMenu floorsPm = new PopupMenu(MapViewActivity.this,btnFloorMenu);

    MenuItem titleItem =  floorsPm.getMenu().add(Menu.NONE, Menu.NONE, Menu.NONE, "Floors");

    int i = 1;
    for(Floor fl : flList)
    {
        floorsPm.getMenu().add(Menu.NONE, i,i, fl.getName());
        if(i>3)
            break;
        i++;
    }


    // add popup listener
    floorsPm.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        //    onClick
        @Override
        public boolean onMenuItemClick(MenuItem item){
            //       get floorname

            int flOrder = item.getOrder();
            if(flOrder == Menu.NONE )
                return true;
            flOrder--;

            final String floorId = …
Run Code Online (Sandbox Code Playgroud)

android popup popupmenu popupwindow android-popupwindow

7
推荐指数
1
解决办法
1347
查看次数