如何更改位置和时间吐司?

时间:2018-06-04 16:28:15

标签: java android

我正在制作一个多项选择测验应用程序,我想改变我的吐司的位置和时间。我已经查看了其他答案,但他们没有帮助,因为我没有制作一个toast实例变量。我不确定我是否应该再次这样做,因为当我第一次这样做时应用程序崩溃了。这是一个按钮的代码:

 b_answer1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //check if the answer is correct
            if (b_answer1.getText().toString().equalsIgnoreCase(list.get(turn - 1).getName())) {
                score++;
                Toast.makeText(FlagQuizActivity.this, "Correct! Your score is: " + score, Toast.LENGTH_LONG).show();



                if (turn < list.size()) {
                    turn++;
                    newQuestion(turn);
                }
                else {
                    Toast.makeText(FlagQuizActivity.this, "You've finished the quiz! Your total score is: " + score, Toast.LENGTH_LONG).show();

                }
            }
            else {
                Toast.makeText(FlagQuizActivity.this, "Incorrect! Your score remains: " + score, Toast.LENGTH_LONG).show();

                if (turn < list.size()) {
                    turn++;
                    newQuestion(turn);
                }
                else {
                    Toast.makeText(FlagQuizActivity.this, "You've finished the quiz! Your total score is: " + score +"/50", Toast.LENGTH_LONG).show();


                }

            }

        }
    });

我应该如何改变吐司的位置和长度? setGravity方法使应用程序崩溃。

1 个答案:

答案 0 :(得分:0)

You can use the getGravity() method as well as the setDuration() method. https://developer.android.com/reference/android/widget/Toast