如何把覆盖在视图的操作栏福尔摩斯福尔摩斯、视图、操作

由网友(北以晨安)分享简介:我想设定一些景色操作栏,将显示教程的文字(就像点击此处,发送邮件...)。这可能吗?我问,因为我知道,行动吧使用的布局顶部空间,片段或活动使用剩余空间。我的第二个问题是如何显示在操作栏的所有行动项目。我用ActionBarSherlock库,我看到,我有空间,多一个操作项,但它不能在动作条上显示。我在项目XML if...

我想设定一些景色操作栏,将显示教程的文字(就像点击此处,发送邮件...)。这可能吗?我问,因为我知道,行动吧使用的布局顶部空间,片段或活动使用剩余空间。 我的第二个问题是如何显示在操作栏的所有行动项目。我用ActionBarSherlock库,我看到,我有空间,多一个操作项,但它不能在动作条上显示。我在项目XML ifRoom选项设置...

I want to set some view over action bar that will display Tutorial text (Like click here and send email...). Is this possible? I ask because i know that action bar uses the top space on layout, and a fragment or activity uses remaining space. My second question is how to display all action items on action bar. I use ActionBarSherlock library and i see that i have room for one more action item, but it's not displaying on action bar. I set in xml ifRoom option on item...

谢谢!

推荐答案

有多种方式来实现的教程式的叠加。也许最简单的一种是使用特殊prepared 对话窗口透明背景,无暗淡后面。

There are multiple ways to achieve a tutorial-like overlay. Probably the easiest one is to use specially prepared Dialog window with transparent background and without dim behind.

首先,我们要为对话框 prepare内容。在这个例子中就会有一个的TextView RelativeLayout的这是最有用的布局位置。

First of all we have to prepare content for the Dialog. In this example there will be one TextView inside RelativeLayout which is the most useful layout here.

info_overlay.xml含量文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@android:color/darker_gray"
        android:padding="3dp"
        android:text="TextView"
        android:textColor="@android:color/white" />

</RelativeLayout>

现在,我们可以用这个布局来创建我们的对话框

Now, we can use this layout to create our Dialog:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Dialog overlayInfo = new Dialog(MainActivity.this);
        // Making sure there's no title.
        overlayInfo.requestWindowFeature(Window.FEATURE_NO_TITLE);
        // Making dialog content transparent.
        overlayInfo.getWindow().setBackgroundDrawable(
                new ColorDrawable(Color.TRANSPARENT));
        // Removing window dim normally visible when dialog are shown.
        overlayInfo.getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        // Setting position of content, relative to window.
        WindowManager.LayoutParams params = overlayInfo.getWindow().getAttributes();
        params.gravity = Gravity.TOP | Gravity.LEFT;
        params.x = 100;
        params.y = 20;
        // If user taps anywhere on the screen, dialog will be cancelled.
        overlayInfo.setCancelable(true);
        // Setting the content using prepared XML layout file.
        overlayInfo.setContentView(R.layout.info_overlay);
        overlayInfo.show();
    }

结果

下面是上述溶液加工的屏幕截图。注意的TextView 动作条

如果你有一个专门的按钮以关闭教程中,你大概可以使用 setCancelable(假)来避免教程意外关闭。 在该解决方案适用于任何操作栏的解决方案的任何主题(无论是操作系统提供的,的 Android的支持库或的ActionBar福尔摩斯的) If you'll have a dedicated button to dismiss tutorial you can probably use setCancelable(false) to avoid accidental closing of tutorial. This solution works with any theme with any action bar solution (either OS-provided, Android Support Library or ActionBar Sherlock)

看看展示查看库,因为它着重于简单的方式创造教程般的画面。我不知道但是,它可以很容易地覆盖其他动作。

Take a look at Showcase View library as it focuses on creating tutorial-like screens in easy way. I'm not sure however that it can easily overlay actionbars.

阅读全文

相关推荐

最新文章