2013-08-09 36 views
6

Tôi là người lập trình mới làm quen và tôi có vấn đề với việc tắt hoạt ảnh hộp thoại (mờ dần và mờ dần).Vô hiệu hóa (mờ dần và mờ dần) hộp thoại hoạt hình

tôi cố gắng để nó sử dụng phong cách trống và đặt nó bằng cách thay đổi

final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 

vào

final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.NoAnimation)); 

Bối cảnh của hộp thoại trở thành màu đen, tích cực và nút negatice đổi thành < 2,1-4,0) phong cách android, nhưng mờ dần và mờ dần hiệu ứng hoạt ảnh vẫn còn ...

Kiểu của tôi:

<style name="DialogNoAnimation"> 
    <item name="android:windowEnterAnimation">@anim/enter</item> 
    <item name="android:windowExitAnimation">@anim/exit</item> 
</style> 

<style name="NoAnimation" parent="@android:style/Theme.Dialog"> 
    <item name="android:windowAnimationStyle">@style/DialogNoAnimation</item> 
</style> 

Bất kỳ ý tưởng nào làm cách nào để loại bỏ hoạt ảnh này?

+0

Có bạn đã cố gắng thêm '@ null' để nhập và xuất hoạt ảnh thay thế? –

+0

hoặc ' @ null' –

+0

Chính xác như hiệu ứng giống như với @ anim/enter và @ anim/exit. Ý tôi là với @ null @ null hoặc @ null Stramek

Trả lời

6

Cuối cùng thành công!

res/anim/enter.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:duration="@android:integer/config_shortAnimTime"/> 

res/anim/exit.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="@android:integer/config_shortAnimTime"/> 

res/values ​​/ styles.xml

<style name="DialogNoAnimation"> 
    <item name="android:windowEnterAnimation">@anim/enter</item> 
    <item name="android:windowExitAnimation">@anim/exit</item> 
</style> 

src/[dialog_box_class ] .java

@Override 
public void onStart() 
{ 
    super.onStart(); 
    if (getDialog() == null) 
    return; 
    getDialog().getWindow().setWindowAnimations(R.style.DialogNoAnimation); 
} 
1

đây là một giải pháp đơn giản:

xác định một phong cách tùy chỉnh trên styles.xml của bạn:

<style name="Dialog"> 
    <item name="android:windowAnimationStyle">@null</item> 
    //... more items 
</style> 

Tạo một người thợ xây mới với phong cách tùy chỉnh của bạn:

AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Dialog); 
builder.setTitle("Dialog title"); 
builder.show(); 

thưởng thức

Các vấn đề liên quan