Je suis en train de mettre en œuvre la screen.Here suivante sur cliquant sur l'icône de pièce jointe, fenêtre est affichée:Impossible de gérer Popup Window dans Android
Je suis en train de mettre en œuvre l'écran en utilisant le Mentionnés ci-dessous Code:
1.popupwindow_attachment.xml
<?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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/padding10"
android:background="@color/while_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/gallery"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding10"
android:drawableTop="@drawable/gallery"
android:gravity="center"
android:text="Gallery" />
<TextView
android:id="@+id/photos"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding10"
android:drawableTop="@drawable/photos"
android:gravity="center"
android:text="Photos" />
<TextView
android:id="@+id/videos"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding10"
android:drawableTop="@drawable/videos"
android:gravity="center"
android:text="Gallery" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/audio"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding10"
android:drawableTop="@drawable/audio"
android:gravity="center"
android:text="Audio" />
<TextView
android:id="@+id/location"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding10"
android:drawableTop="@drawable/location"
android:gravity="center"
android:text="Location" />
<TextView
android:id="@+id/contacts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding10"
android:drawableTop="@drawable/contacts"
android:gravity="center"
android:text="Contacts" />
</LinearLayout>
</LinearLayout>
2.Code mettre en œuvre la fenêtre
private void initializePopUpWindow() {
//inflate the popupwindow_attachment.xml
LinearLayout viewGroup = (LinearLayout) SingleChatActivity.this.findViewById(R.id.popup_element);
LayoutInflater inflater = (LayoutInflater) SingleChatActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popupwindow_attachment, viewGroup);
popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT,true);
//Displaying the popup at a specific location
popupWindow.showAtLocation(layout,Gravity.CENTER,0,0);
}
Je reçois l'écran suivant après avoir utilisé ce code:
Comme vous pouvez le voir ici, la fenêtre pop-up est pas en dessous de la barre d'outils. Aidez-moi s'il vous plaît à résoudre le problème.
Modifié le code:
private void initializePopUpWindow() {
//inflate the popupwindow_attachment.xml
LinearLayout viewGroup = (LinearLayout) SingleChatActivity.this.findViewById(R.id.popup_element);
LayoutInflater inflater = (LayoutInflater) SingleChatActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popupwindow_attachment, viewGroup);
popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
//Displaying the popup at a specific location
// popupWindow.showAtLocation(layout, Gravity.TOP, 0, 150);
popupWindow.showAsDropDown(toolbar,0,0);
//Close the popup when touch outside
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
// popupWindow.dismiss();
}
Après avoir utilisé le code ci-dessus, la fenêtre pop-up est en dessous de la barre d'outils que je veux mais pas fermé après avoir cliqué sur l'extérieur fonctionnalité it.No travaille dans le screen.Screen est juste pendu mal.
Modifié Code du travail:
méthode 1.onCreate()
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_chat);
//Toolbar
toolbar = (Toolbar) findViewById(R.id.toolbarSingleChat);
toolbar.setNavigationIcon(R.drawable.back); // Setting Navigation Icon in the Toolbar
setSupportActionBar(toolbar);
LinearLayout viewGroup = (LinearLayout) SingleChatActivity.this.findViewById(R.id.popup_element);
LayoutInflater inflater = (LayoutInflater) SingleChatActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popupwindow_attachment, viewGroup);
popupWindow = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
//Close the popup when touch outside
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
2.onoptionsItemSelected()
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_viewContacts:
return true;
case R.id.action_media:
return true;
case R.id.action_search:
return true;
case R.id.action_block:
return true;
case R.id.action_email_chat:
return true;
case R.id.action_clear_chat:
return true;
case R.id.action_attach:
initializePopUpWindow();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
méthode 3.initializePopUpWindow() :
private void initializePopUpWindow() {
popupWindow.showAsDropDown(toolbar, 0, 0);
}
Maintenant, cela fonctionne pour moi.
Mais il affichera la fenêtre pop-up sous la vue cliquée. Je veux une fenêtre pop-up en dessous d'une vue spécifique. Dans mon cas, je le veux en dessous de la barre d'outils qui contient une action de pièce jointe. –
exactement de sorte que vous pouvez passer ici vue de la barre d'outils de sorte qu'il sera affiché ci-dessous barre d'outils. Qu'est-ce que tu veux d'autre? – justDroid
: S'il vous plaît vérifier mon code édité. Fenêtre Popup est ajouté avec succès sous la barre d'outils. Mais il n'est pas supprimé après avoir cliqué en dehors de lui. L'écran est juste pendu. Aucune fonctionnalité ne fonctionne. –