In the openActivity() method, you can add the code to start the activity that you want to open when the user clicks on the button.
Code snippet
public void openActivity(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
Save the XML file and compile your project.
When you create a notification, you can use the setCustomContentView() method to set the content view of the notification to the XML layout that you created. This will display the notification with the text and button that you defined in the XML layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Your notification test is successfull !"
android:textSize="18sp" />
</LinearLayout>
Liked By
Write Answer
How to create Xml layout for Notification activity
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Aryan Kumar
27-Jun-2023To create an XML layout for a notification activity, you can use the following steps:
notification_layout.xml
.Code snippet
openActivity()
method, you can add the code to start the activity that you want to open when the user clicks on the button.Code snippet
When you create a notification, you can use the
setCustomContentView()
method to set the content view of the notification to the XML layout that you created. This will display the notification with the text and button that you defined in the XML layout.Samuel Fernandes
27-Jun-2016Hi Jones try this below code