Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在操作栏中显示刷新消息_Android_Android Actionbar - Fatal编程技术网

Android 在操作栏中显示刷新消息

Android 在操作栏中显示刷新消息,android,android-actionbar,Android,Android Actionbar,我使用的是一个普通的动作栏,而不是android应用程序中的sherlock,当应用程序打开时,我想在动作栏中显示一条令人耳目一新的消息。这意味着我想隐藏菜单项和标题,类似于GMail应用程序刷新时的显示方式 最好的方法是什么?它是否使用上下文操作栏 是否可以在动作栏下方显示刷新动画,就像在GMail应用程序ie中,蓝线滑过一样 我知道我可以使用第三方拉刷新,但我不想使用它,因为我不需要拉刷新功能 我的目标是果冻豆和更新的设备 谢谢 我想隐藏与GMail应用程序相似的菜单项和标题 刷新时显示 这

我使用的是一个普通的动作栏,而不是android应用程序中的sherlock,当应用程序打开时,我想在动作栏中显示一条令人耳目一新的消息。这意味着我想隐藏菜单项和标题,类似于GMail应用程序刷新时的显示方式

最好的方法是什么?它是否使用上下文操作栏

是否可以在动作栏下方显示刷新动画,就像在GMail应用程序ie中,蓝线滑过一样

我知道我可以使用第三方拉刷新,但我不想使用它,因为我不需要拉刷新功能

我的目标是果冻豆和更新的设备

谢谢

我想隐藏与GMail应用程序相似的菜单项和标题 刷新时显示

这可以通过使用WindowManager.addViewView、LayoutParams来完成。下面是一个在ActionBar顶部显示消息的示例,它将为您提供一个关于如何继续的非常可靠的想法

布局

结果

结论

这个实现非常类似于Gmail和其他应用程序,不包括拉刷新模式

调用showLoadingMessage时,发布Runnable或使用View.OnClickListener。您不希望过早调用WindowManager.addView,否则将引发WindowManager.BadTokenException。另外,在Activity.ondestory中调用removeLoadingMessage也很重要,否则您可能会泄漏添加到窗口中的视图

我想隐藏与GMail应用程序相似的菜单项和标题 刷新时显示

这可以通过使用WindowManager.addViewView、LayoutParams来完成。下面是一个在ActionBar顶部显示消息的示例,它将为您提供一个关于如何继续的非常可靠的想法

布局

结果

结论

这个实现非常类似于Gmail和其他应用程序,不包括拉刷新模式


调用showLoadingMessage时,发布Runnable或使用View.OnClickListener。您不希望过早调用WindowManager.addView,否则将引发WindowManager.BadTokenException。另外,在Activity.ondestory中调用removeLoadingMessage也很重要,否则您可能会泄漏添加到窗口中的视图。

谢谢。发布为Runnable的目的是什么?@WiseShepherd您不想过早调用WindowManager.addView,否则会抛出WindowManager.BadTokenException@adneal,我可以为从WindowManager.addView创建的视图设置动画吗?我应该在哪里实现动画?@JongzPuangput Yes,在您呼叫WindowManager.addView之后。@adneal感谢您的回答。现在我正在尝试设置动画,但我在android中没有任何动画经验。然而,我正在尝试,但如果你能提供一些例子,那就太好了!谢谢发布为Runnable的目的是什么?@WiseShepherd您不想过早调用WindowManager.addView,否则会抛出WindowManager.BadTokenException@adneal,我可以为从WindowManager.addView创建的视图设置动画吗?我应该在哪里实现动画?@JongzPuangput Yes,在您呼叫WindowManager.addView之后。@adneal感谢您的回答。现在我正在尝试设置动画,但我在android中没有任何动画经验。然而,我正在尝试,但如果你能提供一些例子,那就太好了!
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/message"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textColor="@android:color/white"
    android:textSize="18sp" />
/** The attribute depicting the size of the {@link ActionBar} */
private static final int[] ACTION_BAR_SIZE = new int[] {
        android.R.attr.actionBarSize
};

/** The notification layout */
private TextView mMessage;

private void showLoadingMessage() {
    // Remove any previous notifications
    removeLoadingMessage();

    // Initialize the layout
    if (mMessage == null) {
        final LayoutInflater inflater = getLayoutInflater();
        mMessage = (TextView) inflater.inflate(R.layout.your_layout, null);
        mMessage.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_dark));
        mMessage.setText("Loading...");
    }

    // Add the View to the Window
    getWindowManager().addView(mMessage, getActionBarLayoutParams());
}

private void removeLoadingMessage() {
    if (mMessage != null && mMessage.getWindowToken() != null) {
        getWindowManager().removeViewImmediate(mMessage);
        mMessage = null;
    }
}

/**
 * To use, @see {@link WindowManager#addView(View, LayoutParams)}
 * 
 * @return The {@link WindowManager.LayoutParams} to assign to a
 *         {@link View} that can be placed on top of the {@link ActionBar}
 */
private WindowManager.LayoutParams getActionBarLayoutParams() {
    // Retrieve the height of the status bar
    final Rect rect = new Rect();
    getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    final int statusBarHeight = rect.top;

    // Retrieve the height of the ActionBar
    final TypedArray actionBarSize = obtainStyledAttributes(ACTION_BAR_SIZE);
    final int actionBarHeight = actionBarSize.getDimensionPixelSize(0, 0);
    actionBarSize.recycle();

    // Create the LayoutParams for the View
    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            LayoutParams.MATCH_PARENT, actionBarHeight,
            WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.TOP;
    params.x = 0;
    params.y = statusBarHeight;
    return params;
}