this is a working example of setAnimationStyle() on my end:
Res / anim / in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/decelerate_interpolator"> <translate android:fromYDelta="854" android:toYDelta="0" android:duration="1000"/> </set>
Res / anim / out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:interpolator="@android:anim/decelerate_interpolator" android:fromYDelta="0" android:toYDelta="854" android:duration="10000" /> </set>
layout /main.xml :
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/layout" > <Button android:id="@+id/btn_show" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="show" /> </RelativeLayout >
layout /popup.xml :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#cccccc" > <Button android:id="@+id/btn_dismiss" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="dismiss"/> </LinearLayout>
values /styles.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="PopupAnimation" parent="android:Animation" mce_bogus="1"> <item name="android:windowEnterAnimation">@anim/in</item> <item name="android:windowExitAnimation">@anim/out</item> </style> </resources>
values /strings.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, MainActivity!</string> <string name="app_name">Popupwindow</string> </resources>
MainActivity.java :
public class MainActivity extends Activity { boolean flag =false; PopupWindow popupWindow; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); } public void init() { Button btn_show = (Button) findViewById(R.id.btn_show); LayoutInflater inflater = LayoutInflater.from(this); View layout = inflater.inflate(R.layout.popup, null); popupWindow =new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); Button btn_dismiss = (Button) layout.findViewById(R.id.btn_dismiss); btn_dismiss.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
and in your code just add your animation file to the style:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="test" parent="android:Animation" mce_bogus="1"> <item name="android:windowEnterAnimation">@anim/test</item> </style> </resources>
and in code:
pw.setAnimationStyle(android.R.style.test);
Thanks and happy coding !!!