2016-07-20 16 views
11

Hinweis: Dies ist Popup-Menü nicht Popup-Fenster.So fordere ich Sie alle sorgfältig zu lesen.Set Popup-Menü auf Vollbild

Ich habe Pop-Menü implementiert. Es wird auf der Hälfte des Bildschirms angezeigt. Ich möchte dies auf die gesamte Gerätebreite verteilen. Ich habe versucht, seinen Stil zu ändern, indem ich layout_width als aber ohne Erfolg eingestellt habe.

Unten ist das, was ich bisher versucht:

Stil

<!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 

     <item name="popupMenuStyle">@style/PopupMenu</item> 
    </style> 

    <!-- Change Overflow Menu Background --> 
    <style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow"> 
     <item name="android:popupBackground">#888888</item> 
     <item name="android:layout_width">match_parent</item> 
    </style> 

Unten ist mein Java-Code:

PopupMenu menu = new PopupMenu(getActivity(), tvnext); 


    for (int i = 0; i < array.size(); i++) { 

     menu.getMenu().add(1, i, 1, array.get(i).getAccountName()); 

    } 


    menu.show(); 

    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 
     @Override 
     public boolean onMenuItemClick(MenuItem item) { 
      setUpNextFunctionality(item.getItemId()); 


      return false; 
     } 
    }); 

P. S: Bitte nicht schlagen mir Popup-Fenster zu verwenden. Dies ist meine letzte Option, wenn nichts funktioniert.

+0

Sie Antworten von unten Link finden http://stackoverflow.com/questions/24466869/android-popup -window-full-screen –

+0

versuchen, meine Frage zu lesen. Es ist Popup-Menü nicht Fenster. Ich erwähne besonders den Hinweis am Ende der Frage. – theLazyFinder

+0

Schöne Frage ...... Laut mir ist das nicht möglich .... Versuch in meinem Projekt, wie Sie wollen, aber konnte nicht Erfolg ..... Ich bin mehr für Ihre Frage ....... Wenn Sie Erfolg haben, dann setzen Sie Ihre Antwort, die für mich interessant war .... wenn jemand dies gemäß Ihrer Anforderung beantworten wird schätzen ... –

Antwort

1

Trythis:

pwindow = 
    new PopupWindow(layoutt,LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,true); 
+0

versuchen Sie, meine Frage zu lesen. Es ist Popup-Menü nicht Fenster. Ich erwähne besonders den Hinweis am Ende der Frage. – theLazyFinder

0

dies versuchen,

inflater.inflate (R.layout.menu, Menü);

oder

menu.inflate (R.layout.popup_menu);

+0

Willkommen in SO Ravina. Aber leider wird dies zum Aufpumpen des Menüs benutzt (aus R.menu). Das wird uns nicht helfen, ein benutzerdefiniertes Layout zu erstellen. – theLazyFinder

2

Ich glaube nicht, dass Sie das tun können, ohne Ihr eigenes Popup-Fenster ähnlich PopupMenu zu implementieren. Wenn Sie MenuPopupHelper::createPopup überprüfen werden:

@NonNull 
private MenuPopup createPopup() { 
    final WindowManager windowManager = (WindowManager) mContext.getSystemService(
      Context.WINDOW_SERVICE); 
    final Display display = windowManager.getDefaultDisplay(); 
    final Point displaySize = new Point(); 

    if (Build.VERSION.SDK_INT >= 17) { 
     display.getRealSize(displaySize); 
    } else if (Build.VERSION.SDK_INT >= 13) { 
     display.getSize(displaySize); 
    } else { 
     displaySize.set(display.getWidth(), display.getHeight()); 
    } 

    final int smallestWidth = Math.min(displaySize.x, displaySize.y); 
    final int minSmallestWidthCascading = mContext.getResources().getDimensionPixelSize(
      R.dimen.abc_cascading_menus_min_smallest_width); 
    final boolean enableCascadingSubmenus = smallestWidth >= minSmallestWidthCascading; 

    final MenuPopup popup; 
    if (enableCascadingSubmenus) { 
     popup = new CascadingMenuPopup(mContext, mAnchorView, mPopupStyleAttr, 
       mPopupStyleRes, mOverflowOnly); 
    } else { 
     popup = new StandardMenuPopup(mContext, mMenu, mAnchorView, mPopupStyleAttr, 
       mPopupStyleRes, mOverflowOnly); 
    } 

    // Assign immutable properties. 
    popup.addMenu(mMenu); 
    popup.setOnDismissListener(mInternalOnDismissListener); 

    // Assign mutable properties. These may be reassigned later. 
    popup.setAnchorView(mAnchorView); 
    popup.setCallback(mPresenterCallback); 
    popup.setForceShowIcon(mForceShowIcon); 
    popup.setGravity(mDropDownGravity); 

    return popup; 
} 

werden Sie die Größe von PopupMenu Art fest einprogrammiert wie pro Anzeigegröße sehen. So ist es wahrscheinlich einfach, PopupMenu bezogenen Quellcode zu überprüfen und etwas ähnliches zu implementieren, aber mit Größen, die Sie haben möchten.

+0

So verwenden Sie ... – theLazyFinder

+0

@tpA Was zu verwenden? – Divers

+0

Wie kann ich diese Methode in meiner Fragmentklasse verwenden? Ich habe in meiner Klasse kopiert, konnte aber MenuPopup nicht importieren. Ist es eingebaute Klasse – theLazyFinder

1

Versuchen Sie, so minWidth in Ihrem Stil zu setzen unter

 <item name="android:minWidth">1000dp</item> 
+0

nicht funktioniert ..... – theLazyFinder

5

ich Ihre Frage bekam. Anstatt etwas zu ändern, benutze ein neues Widget, das deine notwendige und kompatible Version mit neuerer Version leicht erfüllen kann.

Google neues Materialkonzept vorstellen als Bottom-Sheet

Um es in Android verwenden, können Sie git Hub-Bibliotheken wie this verwenden.

0

Durchscheinend machen. Ich habe das gleiche für Pop-up gemacht. Bitte überprüfen Sie dieses. Vielleicht funktioniert es auch für dich.

In Ihrem Manifest:

<activity 
      android:name=".ActivityInviteFriend" 
      android:theme="@style/Theme.TransparentInfo"> 

     </activity> 

Im Stil: Hauptthema:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/LightappActionBarColor</item> 
     <item name="colorPrimaryDark">@color/appColor</item> 
     <item name="colorAccent">@color/btn_color</item> 
     <item name="windowNoTitle">true</item> 
     <item name="windowActionBar">false</item> 
    </style> 

und Ihr eigenes Thema:

<color name="semiTransparentBlack">#00000000</color> 

    <style name="Theme.TransparentInfo" parent="AppTheme"> 
     <item name="android:windowIsTranslucent">true</item> 
     <item name="android:windowBackground">@color/semiTransparentBlack</item> 
     <item name="android:windowContentOverlay">@null</item> 
     <item name="android:windowNoTitle">true</item> 
     <item name="android:windowIsFloating">false</item> 
     <item name="android:backgroundDimEnabled">true</item> 
    </style> 

Ihre Aktivität:

package com.gc.naifizzy; 

import android.graphics.drawable.ColorDrawable; 
import android.os.Bundle; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.view.View; 
import android.view.Window; 
import android.widget.Button; 
import android.widget.Toast; 

public class ActivityInviteFriend extends AppCompatActivity { 
    Button btn_send; 
    Snackbar snackbar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setBackgroundDrawable(
       new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
     setContentView(R.layout.activity_invite_friend); 
     btn_send = (Button) findViewById(R.id.btn_send); 
     btn_send.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       //snack("Invitation sent successfully..."); 
       Toast.makeText(ActivityInviteFriend.this, "Invitation sent successfully", Toast.LENGTH_SHORT).show(); 
       finish(); 
      } 
     }); 
    } 

    public void snack(String data) { 
     snackbar = Snackbar 
       .make(findViewById(android.R.id.content), data, Snackbar.LENGTH_LONG) 
       .setAction("Dismiss", new View.OnClickListener() { 
        @Override 
        public void onClick(View view) { 
         snackbar.dismiss(); 
        } 
       }); 

     snackbar.show(); 

    } 
} 

und Ihre xml Layout schließlich:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#502f2f2f"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:layout_centerInParent="true" 
     android:background="@android:color/white" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp"> 

     <RelativeLayout 
      android:id="@+id/dds" 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:background="#112f2f2f" 
      android:paddingTop="10dp" 
      android:visibility="visible"> 


      <TextView 
       android:id="@+id/txt_what" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_centerVertical="true" 
       android:gravity="center_vertical|left" 
       android:paddingLeft="10dp" 
       android:text="Invite people to join your tree on Naifizzy" 
       android:textColor="@color/appColor" 
       android:textSize="15sp" 
       android:textStyle="bold" /> 

     </RelativeLayout> 

     <View 
      android:id="@+id/view" 
      android:layout_width="match_parent" 
      android:layout_height="3dp" 
      android:layout_below="@id/dds" 
      android:layout_marginTop="3dp" 
      android:alpha="0.5" 
      android:background="@color/appColor" 
      android:visibility="visible" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/view" 
      android:layout_marginTop="20dp" 
      android:gravity="center_vertical|center_horizontal" 
      android:orientation="vertical"> 

      <TextView 
       android:id="@+id/txt_share" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="10dp" 
       android:text="Invite people by sharing this link " 
       android:textColor="#992f2f2f" 
       android:textSize="15sp" /> 

      <EditText 
       android:id="@+id/edt_user_link" 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_below="@id/txt_share" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="10dp" 
       android:background="@drawable/layout_border" 
       android:editable="false" 
       android:paddingLeft="10dp" 
       android:singleLine="true" 
       android:text="http://naifizzy.com/@parik_dhakan" 
       android:textColor="#992f2f2f" 
       android:textSize="15sp" /> 

      <View 
       android:id="@+id/view1" 
       android:layout_width="match_parent" 
       android:layout_height="1dp" 
       android:layout_below="@id/edt_user_link" 
       android:layout_marginBottom="20dp" 
       android:layout_marginTop="20dp" 
       android:alpha="0.5" 
       android:background="@color/appColor" /> 

      <TextView 
       android:id="@+id/txt_share2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/view1" 
       android:layout_centerVertical="true" 
       android:layout_marginLeft="10dp" 
       android:text="Send by email " 
       android:textColor="#992f2f2f" 
       android:textSize="15sp" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:layout_marginBottom="30dp" 
       android:layout_marginTop="10dp" 
       android:orientation="horizontal" 
       android:visibility="visible" 
       android:weightSum="1"> 

       <LinearLayout 
        android:id="@+id/ed_l" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_weight="0.2" 
        android:background="@drawable/layout_border" 
        android:orientation="horizontal" 
        android:visibility="visible"> 

        <RelativeLayout 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 


         <android.support.design.widget.TextInputLayout 
          android:id="@+id/edl_current" 
          android:layout_width="match_parent" 
          android:layout_height="match_parent" 
          android:layout_centerInParent="true" 

          android:paddingTop="5dp" 
          android:textColorHint="#992f2f2f" 
          android:textSize="15sp"> 

          <EditText 
           android:id="@+id/edt_mail" 
           style="@style/StyledTilEditText" 
           android:layout_width="match_parent" 
           android:layout_height="match_parent" 
           android:layout_centerHorizontal="true" 
           android:background="@android:color/transparent" 
           android:hint="Enter recipients' Email seprated by commas " 
           android:inputType="textEmailAddress" 
           android:paddingLeft="10dp" 
           android:textColor="#992f2f2f" 
           android:textColorHint="#992f2f2f" 

           android:textSize="15sp" /> 
         </android.support.design.widget.TextInputLayout> 

         <ImageView 
          android:id="@+id/img_show" 
          android:layout_width="30dp" 
          android:layout_height="25dp" 
          android:layout_alignParentEnd="true" 
          android:layout_centerVertical="true" 
          android:layout_marginEnd="20dp" 
          android:scaleType="centerInside" 
          android:src="@drawable/ic_eye" 
          android:visibility="gone" /> 
        </RelativeLayout> 
       </LinearLayout> 

       <EditText 
        android:id="@+id/edt_user_link2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_below="@id/txt_share2" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:background="@drawable/layout_border" 

        android:paddingLeft="10dp" 
        android:singleLine="true" 
        android:text="http://naifizzy.com/@parik_dhakan" 
        android:textColor="#992f2f2f" 
        android:textSize="15sp" 
        android:visibility="gone" /> 

       <Button 
        android:id="@+id/btn_send" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginRight="5dp" 
        android:layout_weight="0.8" 
        android:background="@drawable/signupbg" 
        android:gravity="center_vertical|center_horizontal" 
        android:text="Send\nInvites" 
        android:textColor="@android:color/white" 
        android:textSize="10sp" /> 
      </LinearLayout> 


     </LinearLayout> 
    </RelativeLayout> 


</RelativeLayout> 
+0

Ihr Ansatz ist in gewissem Umfang richtig. Aber Erstellen einer anderen Aktivität eigenen separaten Lebenszyklus und für meine Situation möchte ich das Popup-Fenster in einem anderen Thread. – theLazyFinder