如何在按钮点击时调用或弹出片段

raj*_*war 7 android popup button android-fragments

我实现了一个Android应用程序.我想在评级按钮点击时调用或弹出片段.

例如,这里我附上了截图.当我点击率按钮时,如何调用这样的弹出窗口或片段

在此输入图像描述

在此输入图像描述

请帮我怎么称这些片段?

Anu*_*Anu 6

您需要设计另一个布局,仅用于显示弹出窗口并使其成为alignparenttop.这是示例布局

创建新的xml文件dialog.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLyt"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#FFFFFF"
        android:paddingTop="10dp" >

        <TextView
            android:id="@+id/close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="Fill in your design in this place"
            android:textSize="10dp" />


    </RelativeLayout>

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

一旦你创建了你的设计.你需要在你的onbutton点击中调用它.以下是显示对话的示例

ratingButton.setOnCLickListener(new view.OnCLickListener(){ 
    @Override 
    public void onCLick(View v){
         final Dialog fbDialogue = new Dialog(ProfileActivity.this, android.R.style.Theme_Black_NoTitleBar);
            fbDialogue.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(100, 0, 0, 0)));
            fbDialogue.setContentView(R.layout.facebook_dialogue);
            fbDialogue.setCancelable(true);
            fbDialogue.show();
    } 
}); 


    Hey I have put the code in onclicklistener. Check it . The above code works perfectly fine for me. As per my requirement I wanted the dialogue on the bottom of the screen . I have just made few lines of code change above to meet your requirement. My requirement was something like this   
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述