【问题标题】:how to create a helper screen in android如何在android中创建一个帮助屏幕
【发布时间】:2016-08-30 06:29:36
【问题描述】:

我想在主要活动上获得一个帮助屏幕,以便用户指导如何使用应用程序。

这是我的主要活动。

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

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

【问题讨论】:

标签: android android-layout main-activity


【解决方案1】:

我对你的代码做了一些修改。

这是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);
        }
    }
}

你需要像这样创建 图像,我在这个例子中使用。

这是输出

【讨论】:

    【解决方案2】:

    您可以通过以下两种方式做到这一点:
    1.根据要求制作带有元素(视图)定位的对话框,并将对话框显示为帮助教程屏幕。
    2. 通过为所有分辨率设备制作帮助屏幕图像并将其用作帮助屏幕。

    【讨论】:

      【解决方案3】:

      您可以使用外部库,例如this one。还有很多其他的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多