Ich mag den Ansatz in Kostya But's answer.
Aufbauend auf, dass hier ein paar Ideen, um die gleiche Overlay leicht wiederverwendbar über Ihre App zu machen:
Betrachten Sie das Overlay FrameLayout in einem separaten Layout-Datei setzen, z.B.res/layout/include_progress_overlay
.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progress_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.4"
android:animateLayoutChanges="true"
android:background="@android:color/black"
android:clickable="true"
android:visibility="gone">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>
(Eine Sache, die ich in der Overlay hinzugefügt FrameLayout android:clickable="true"
ist Während also die Überlagerung angezeigt wird, verhindert, dass Klicks auf UI-Elemente darunter durchläuft zumindest in meinem typischen Anwendungsfall das ist, was ich. wollen)
Dann ist es enthalten, wo nötig.
<!-- Progress bar overlay; shown while login is in progress -->
<include layout="@layout/include_progress_overlay"/>
Und in Code:
View progressOverlay;
[...]
progressOverlay = findViewById(R.id.progress_overlay);
[...]
// Show progress overlay (with animation):
AndroidUtils.animateView(progressOverlay, View.VISIBLE, 0.4f, 200);
[...]
// Hide it (with animation):
AndroidUtils.animateView(progressOverlay, View.GONE, 0, 200);
Mit Code-Animation in eine util Verfahren extrahiert:
/**
* @param view View to animate
* @param toVisibility Visibility at the end of animation
* @param toAlpha Alpha at the end of animation
* @param duration Animation duration in ms
*/
public static void animateView(final View view, final int toVisibility, float toAlpha, int duration) {
boolean show = toVisibility == View.VISIBLE;
if (show) {
view.setAlpha(0);
}
view.setVisibility(View.VISIBLE);
view.animate()
.setDuration(duration)
.alpha(show ? toAlpha : 0)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(toVisibility);
}
});
}
(hier view.animate()
verwenden, hinzugefügt in API 12, statt AlphaAnimation
.)
Sie sind für diese suchen? Recht ? http://stackoverflow.com/questions/2176922/how-to-create-transparent-activity-in-android –
@ M-WaJeEh Wie füge ich Text und/oder Grafiken zu dieser Aktivität hinzu? –
wie du zu einer normalen 'Aktivität' hinzufügst. Es ist nur eine normale "Aktivität" mit einem anderen Thema. –