Android Pop-up Penceresi nasıl oluşturulur?
Merhaba dostlar bugün android’de pop-up penceresi nasıl oluşturulur onu konuşacağız. Oluşturacağımız pop-up penceresi bir button ile tetiklenecek ve içinde bir gif ve kapatma düğmesi olacak. Hemen aşamalarına geçelim. Android’de gif oynatmanın anlatımı için şu yazımı okuyabilirsiniz.
İlk aşama olarak .xml dosyamızı oluşturalım. Bunun için android studio’yu açalım, projemizin layout klasörüne sağ tıklayarak şu yolu izleyelim; new>XML>Layout Xml File. Yeni xml dosyamıza popup.xml ismini verelim.
popup.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/common_google_signin_btn_text_dark_default" android:orientation="vertical"> <pl.droidsonroids.gif.GifImageView android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/bicyle" android:textAlignment="center" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" tools:ignore="MissingConstraints" tools:layout_constraintLeft_creator="1" tools:layout_constraintRight_creator="1" tools:layout_constraintTop_creator="1" app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp" app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp" app:layout_constraintVertical_bias="0.0" app:layout_constraintHorizontal_bias="0.0" /> <Button android:id="@+id/dismiss" android:layout_width="46dp" android:layout_height="wrap_content" android:layout_marginTop="-3dp" android:background="@android:drawable/ic_menu_close_clear_cancel" app:layout_constraintTop_toTopOf="parent" tools:ignore="MissingConstraints" android:layout_marginRight="8dp" app:layout_constraintRight_toRightOf="parent" android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintHorizontal_bias="1.0" /> </android.support.constraint.ConstraintLayout> |
Buttonumuz ile tetiklenecek popup ekranının xml’ini oluşturduk. Şimdi popup ekranımızın ortaya çıkmasını istediğimiz java dosyasındaki değişiklere geçelim. Konuştuğumuz gibi bir button ile tetiklenecek popup ekranımız. O yüzden Button ımızın setOnClickListener‘ı içine yazıyoruz kodlarımızı.
mainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | final Button btnPopup = (Button) findViewById(R.id.btnPopup); btnPopup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LayoutInflater layoutInflater = (LayoutInflater)getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE); View popupView = layoutInflater.inflate(R.layout.popup, null); final PopupWindow popupWindow = new PopupWindow( popupView, DrawerLayout.LayoutParams.FILL_PARENT, DrawerLayout.LayoutParams.FILL_PARENT); Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss); //xml imizdeki button'ımız, popup ı kapatmaya yaracak btnDismiss.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v){ // TODO Auto-generated method stub popupWindow.dismiss(); } }); popupWindow.showAsDropDown(btnPopup, 50, 50); } }); |
Evet dostlar bu gün popup’lar hakkında konuşmuş olduk, umarım işinize bir uygulamada yarar ve kullanırsınız. Tatlı kodlar dilerim.