如何在android中创建助手屏幕

我想获得有关主要活动的帮助屏幕,以供用户指导如何使用该应用程序.

这是我的主要活动.

This is my main activity

输出:这是我想向用户显示帮助器屏幕的方式.

This is want I want show to user's while using my app

这是我的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>

解决方法:

我已经对您的代码进行了一些修改.

这是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


这是输出.

enter image description here

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...