Here is the full code for In the button_gradient.xml file in your res/drawable directory, you can define the gradient like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FF3366"
android:endColor="#FF9933"
android:angle="45" />
</shape>
Background XML Design Code background.xml file in your res/drawable directory
Picture
1 2 3 | <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > |
Open styles.xml file and add the following code.
- Open your project's
resdirectory. - Inside the
resdirectory, locate thevaluesdirectory. - Create a new file named
styles.xmlinside thevaluesdirectory. - Open the
styles.xmlfile. - Add the following content to define the 'DialogAnimation' style:
<resources>
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@android:anim/slide_in_left</item>
<item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
</style>
</resources>
Java Code :
1 2 3 | private void showAlertDialog() { |
In the code above, replace parentLayout with the actual layout where you want to add the dynamically created LinearLayout. Also, make sure to replace R.drawable.recyclerview_background_cell, R.drawable.edit_show_icon, R.drawable.button_gradient, and R.color.black with the respective resource identifiers in your project.
The dpToPx() method is a utility method to convert density-independent pixels (dp) to pixels (px). You can define this method as follows:
1 2 3 | private int dpToPx(int dp) { |