安卓开发-使用说明弹窗提示

需求:

需要在应用中展示一个简单的使用说明,主要是业务上由于使用本应用前要先下载一个其他应用。

由于刚入门安卓开发等原因,使用最小成本简单实现,效果如下。

Activity.java中主要代码如下, 在onCreate()中调用initEvent();

注意:模拟器第一次运行时复制没有成功,系统提示无法获得剪贴板,但重启应用后复制成功且无错误提示。功能还未在用户手机上进行验证,问题是否会复现未知。

 private void initEvent() {
        findViewById(R.id.hint_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showDialog();
            }
        });
    }

    private void showDialog(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle("使用说明");
        builder.setMessage(
                "请提前下载应用并进行连接,可点击下方复制按钮复制下载连接到网页打开进行下载。");
        builder.setPositiveButton("复制下载连接",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        copyDownloadLink();
                        showToast("复制成功");
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    private void copyDownloadLink() {
        // Gets a handle to the clipboard service.
        if (null == mClipboard) {
            mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        }
        // Creates a new text clip to put on the clipboard
        ClipData clip = ClipData.newPlainText("download link","http://www.baidu.com");
        // Set the clipboard's primary clip.
        mClipboard.setPrimaryClip(clip);
    }

    /** 
    *   这里的showToast方法是由于业务中用户使用的手机在输入密码时,
    *   提示在下方会被键盘遮挡,故将提示移到了上方。
    *   但本方法在模拟器中不生效,toast仍会在下方进行展示,
    *   但模拟器中toast会在键盘上方进行展示故未进行问题排查。
    */
    private void showToast(String text) {
        Toast toast = Toast.makeText(LoginActivity.this, text, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.TOP, 0, 100);
        toast.show();
    }

activity对应的xml中代码如下,由于右上角对齐在模拟器中有问题,且我对这一块不太熟悉照搬如下。部分是直接在Design中直接拖动的。

<Button
    android:id="@+id/hint_btn"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:layout_gravity="top|right|end"
    android:ems="10"
    android:text="使用说明"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.885"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/guideline7" />

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/guideline7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.05" />

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值