2016-07-20 8 views
11

नोट: यह पॉपअप मेनू पॉपअप विंडो नहीं है। इसलिए मैं आप सभी को ध्यान से पढ़ने के लिए अनुरोध करता हूं।पूर्ण स्क्रीन पर पॉपअप मेनू सेट करें

मैं पॉप मेनू लागू किया है। यह स्क्रीन के आधे में प्रदर्शित हो रहा है। मैं इसे डिवाइस की पूरी चौड़ाई में फैलाना चाहता हूं। मैंने layout_width को match_parent के रूप में सेट करके अपनी शैली बदलने की कोशिश की लेकिन बिना किसी सफलता के।

नीचे क्या मैं अब तक की कोशिश की है:

शैली

<!-- 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> 

नीचे मेरी जावा कोड है:

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; 
     } 
    }); 

पी.एस: कृपया मुझे पॉपअप विंडो का उपयोग करने का सुझाव नहीं है। यदि कुछ भी काम नहीं करता है तो यह मेरा आखिरी विकल्प है।

+0

आप लिंक नीचे से http://stackoverflow.com/questions/24466869/android-popup जवाब मिल जाएगा -विंडो-पूर्ण-स्क्रीन –

+0

मेरे प्रश्न को पढ़ने का प्रयास करें। यह पॉपअप मेनू खिड़की नहीं है। मैं विशेष रूप से प्रश्न के अंत में नोट का उल्लेख करता हूं। – theLazyFinder

+0

अच्छा सवाल ...... मेरे अनुसार यह संभव नहीं है .... जैसा कि आप चाहते हैं मेरी परियोजना में कोशिश कर रहा है लेकिन सफलता नहीं मिल सका ..... मैं आपके प्रश्न के लिए और अधिक जांच कर रहा हूं ....... अगर आपको अपना जवाब देने से सफलता मिली है जो मेरे लिए दिलचस्प था .... अगर कोई आपकी आवश्यकता के हिसाब से इसका उत्तर देता है तो सराहना करता है ..... –

उत्तर

1

Trythis:

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

के रूप में आजमाएं मेरे प्रश्न को पढ़ने का प्रयास करें। यह पॉपअप मेनू खिड़की नहीं है। मैं विशेष रूप से प्रश्न के अंत में नोट का उल्लेख करता हूं। – theLazyFinder

0

इस कोशिश,

inflater.inflate (R.layout.menu, मेनू);

या

menu.inflate (R.layout.popup_menu);

+0

SO Ravina में आपका स्वागत है। लेकिन दुर्भाग्यवश इसका उपयोग मेनू को बढ़ाने के लिए किया जाता है (आरमेनू से)। तो यह कस्टम लेआउट सेट करने में हमारी मदद नहीं करेगा। – theLazyFinder

2

मुझे नहीं लगता कि आप कर सकते हैं है कि अपनी खुद की पॉपअप PopupMenu के समान विंडो के लागू करने के बिना। आप MenuPopupHelper::createPopup की जाँच करेगा हैं:

@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; 
} 

आप प्रदर्शन आकार के अनुसार hardcoded की PopupMenu तरह का है कि आकार देखेंगे। तो संभवतः PopupMenu संबंधित स्रोत कोड की जांच करना और कुछ समान कार्यान्वित करना आसान तरीका है, लेकिन आकारों के साथ जो आप चाहते हैं।

+0

इसका उपयोग कैसे करें ... – theLazyFinder

+0

@tpA क्या उपयोग करने के लिए? – Divers

+0

मैं इस विधि का उपयोग अपने खंड वर्ग में कैसे कर सकता हूं। मैं अपनी कक्षा में कॉपी करता था लेकिन मेनूपॉप आयात करने में सक्षम नहीं था। क्या यह अंतर्निर्मित वर्ग – theLazyFinder

1

रूप

नीचे
 <item name="android:minWidth">1000dp</item> 
+0

काम नहीं कर रहा ..... – theLazyFinder

5

मैं आपके सवाल का मिला अपनी शैली में minWidth स्थापित करने के लिए प्रयास करें। कुछ संशोधित करने के बजाय नए विजेट का उपयोग करें जो आपके संस्करण को आसानी से पूरा कर सकता है और नए संस्करण के साथ संगत हो सकता है। के रूप में Bottom-Sheet

एंड्रॉयड में इसका इस्तेमाल करने के लिए आप this तरह Git हब पुस्तकालयों का उपयोग कर सकते हैं

गूगल नई सामग्री अवधारणा लागू।

0

यह पारदर्शी बनाओ। मैंने इस तरह पॉप अप के लिए भी बनाया है। कृपया इसे जांचें। यह आपके लिए भी काम हो सकता है।

अपने प्रकट में:

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

     </activity> 

शैली में: मुख्य विषय:

<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> 

और अपने कस्टम विषय:

<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> 

आपका गतिविधि:

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(); 

    } 
} 

और अंत में अपने XML लेआउट:

<?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

आपका दृष्टिकोण कुछ हद तक सही है। लेकिन एक और गतिविधि का निर्माण अलग जीवन चक्र है और मेरी स्थिति के लिए मैं उस पॉपअप विंडो को किसी अन्य थ्रेड में चाहता हूं। – theLazyFinder

संबंधित मुद्दे