打开App Android时如何显示消息Toast

时间:2016-02-01 17:33:55

标签: android

我在应用程序中进行逆向工程以将其翻译为我的本地语言我想在Android上打开应用程序时显示要显示的Toast消息

示例Toast text"由Crypton翻译" <<<我想把这条消息放在Toast上

2 个答案:

答案 0 :(得分:0)

XML文件:

<LinearLayout 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"
        android:id="@+id/custom_toast_container"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="8dp"
        android:background="#DAAA"
        >

    <TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFF"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>

Java文件:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String str="Welcome TO MSIT";enter code here
        Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
    }
}

答案 1 :(得分:-1)

String str="translated by Crypton";
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
相关问题