如何在安卓系统中创建帮助屏幕

3
我希望在主活动上添加一个帮助屏幕,以指导用户如何使用该应用程序。
这是我的主要活动界面。 这是我的主要活动界面 输出:这是我想向用户展示的帮助屏幕。 这是我想向用户展示的帮助屏幕 这是我的main_activity.xml文件包含的代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

这是我的MainActivity Java类文件,包含以下代码。
public class MainActivity extends AppCompatActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);//Menu Resource, Menu
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.clipboard:
                Toast.makeText(getApplicationContext(),"Text Copied",Toast.LENGTH_LONG).show();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

这是main_menu.xml文件的内容。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">

    <item
        android:id="@+id/clipboard"
        android:icon="@drawable/ic_content_copy_white_48dp"
        android:orderInCategory="100"
        android:title="Clip Board"
        app:showAsAction="always" />

</menu>

https://dev59.com/tGkv5IYBdhLWcg3w_Vmn - David
3个回答

2
我已经对你的代码进行了一些修改。
以下是activity_main.xml的样子。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="eflair.helperscreentutorial.MainActivity">


    <Button
        android:id="@+id/newButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="New Button" />

    <FrameLayout
        android:id="@+id/fullScreenLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

这里是MainActivity.java的样子。
public class MainActivity extends AppCompatActivity {

    private FrameLayout fullScreenLayout;

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

        fullScreenLayout = (FrameLayout) findViewById(R.id.fullScreenLayout);

        final RelativeLayout layout = new RelativeLayout(this);         // Dynamically creating layout
        layout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams
                .MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        layout.setBackgroundColor(Color.DKGRAY);                        // Setting bgcolor to the layout
        layout.setAlpha(0.5f);                                          // Setting opacity to the layout
        layout.setBackgroundResource(R.drawable.helperscreen);          // Adding image to layout
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fullScreenLayout.removeView(layout);                    // On clicking the image layout will be removed
            }
        });
        fullScreenLayout.addView(layout);                               // Adding view to the layout

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.cb:
                Toast.makeText(getApplicationContext(), "Text Copied", Toast.LENGTH_LONG).show();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}

你需要创建像我在这个例子中使用的图像,就像这样。 输入图像描述 这是输出结果

enter image description here


1
您可以通过以下两种方式实现此操作:
1.根据要求定位元素(视图)并将对话框显示为帮助教程屏幕。
2.为所有分辨率设备制作帮助屏幕图像,并将它们用作帮助屏幕。

0

你可以使用外部库,比如这个。还有很多其他的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接