Android Studio memo that you want to display Toast characters in large size

Press the button to switch the three images in order I made an app that gives different Toast texts.

package com.example.rswitch;

import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View;

import android.widget.ImageView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

// boolean Boolean type that can contain true or false // isShowing Determine if it is displayed on the screen

// Let the computer determine that the images re1 and re2 are displayed on the screen boolean re1IsShowing = true; boolean re2IsShowing = true;

public void fade (View view) {

// Associate Java variables re1, re2, re3 with xml id respectively // Animation will not be executed unless linked ImageView re1 = findViewById(R.id.re1); ImageView re2 = findViewById(R.id.re2); ImageView re3 = findViewById(R.id.re3);

    if(re1IsShowing) {

//swichボタン押した後、画像re1は表示されていないと判定させる re1IsShowing = false;

        re1.animate().alpha(0).setDuration(1000);
        re2.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Cute?", Toast.LENGTH_LONG) .show ();

    } else if(re2IsShowing) {

//swichボタン押した後、画像re2は表示されていないと判定させる re2IsShowing = false;

        re2.animate().alpha(0).setDuration(1000);
        re3.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Play ~", Toast.LENGTH_LONG) .show ();

    } else {

        re1IsShowing = true;
        re2IsShowing = true;


        re3.animate().alpha(0).setDuration(1000);
        re1.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Do you look good?", Toast.LENGTH_LONG) .show (); }

}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);





}

}

However, the text is small, so I want to make it larger. Refer to the article that appeared on the net https://blog.fujiu.jp/2013/11/14-android-toast.html

Try changing text and toast

package com.example.rswitchtoastarrange;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle; import android.view.View;

import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

// boolean Boolean type that can contain true or false // isShowing Determine if it is displayed on the screen

// Let the computer determine that the images re1 and re2 are displayed on the screen boolean re1IsShowing = true; boolean re2IsShowing = true;

TextView text = new TextView(getApplicationContext());



public void fade (View view) {

// Associate Java variables re1, re2, re3 with xml id respectively // Animation will not be executed unless linked ImageView re1 = findViewById(R.id.re1); ImageView re2 = findViewById(R.id.re2); ImageView re3 = findViewById(R.id.re3);

    if(re1IsShowing) {

//swichボタン押した後、画像re1は表示されていないと判定させる re1IsShowing = false;

        re1.animate().alpha(0).setDuration(1000);
        re2.animate().alpha(1).setDuration(1000);

text.setText ("Cute?"); text.setTextSize(30);

        Toast toast = new Toast(getApplicationContext());
        toast.setView(text);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.show();


    } else if(re2IsShowing) {

//swichボタン押した後、画像re2は表示されていないと判定させる re2IsShowing = false;

        re2.animate().alpha(0).setDuration(1000);
        re3.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Play ~", Toast.LENGTH_LONG) .show ();

    } else {

        re1IsShowing = true;
        re2IsShowing = true;


        re3.animate().alpha(0).setDuration(1000);
        re1.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Do you look good?", Toast.LENGTH_LONG) .show (); }

}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);





}

}

If you run as, the app will drop immediately after starting the app on the emulator even though no error occurs.

Looking at Logcat,

2020-01-24 20:10:35.166 1835-1835/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument 2020-01-24 20:10:35.167 1835-1835/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument

I looked it up, but I'm not sure.

Copy and paste the reference article as it is

package com.example.toastbig;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color; import android.graphics.Typeface; import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);




    TextView text = new TextView(getApplicationContext());

//Toastに表示する文字 text.setText ("\ large red text /"); //フォントの種類 text.setTypeface(Typeface.SANS_SERIF); //フォントの大きさ text.setTextSize(30); //フォントの色 text.setTextColor(Color.RED); //文字の背景色(ARGB) text.setBackgroundColor(0x88dcdcdc);

//Toastの表示 Toast toast = new Toast(getApplicationContext()); toast.setView(text); toast.setDuration(Toast.LENGTH_LONG); toast.show(); }

}

Then \ large red letters /

Is displayed properly.

public class MainActivity extends AppCompatActivity Not in

protected void onCreate(Bundle savedInstanceState) { I wondered if I had to put the code inside,

Below TextView protected void onCreate(Bundle savedInstanceState) { In setContentView(R.layout.activity_main);

When I move it to public void fade (View view) To view cannot find symbol and An error has occurred.

package com.example.rswitchtoastarrange;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle; import android.view.View;

import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

// boolean Boolean type that can contain true or false // isShowing Determine if it is displayed on the screen

// Let the computer determine that the images re1 and re2 are displayed on the screen boolean re1IsShowing = true; boolean re2IsShowing = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView text = new TextView(getApplicationContext());



    
    public void fade (View view) {

// Associate Java variables re1, re2, re3 with xml id respectively // Animation will not be executed unless linked ImageView re1 = findViewById(R.id.re1); ImageView re2 = findViewById(R.id.re2); ImageView re3 = findViewById(R.id.re3);

        if(re1IsShowing) {

//swichボタン押した後、画像re1は表示されていないと判定させる re1IsShowing = false;

            re1.animate().alpha(0).setDuration(1000);
            re2.animate().alpha(1).setDuration(1000);

text.setText ("Cute?"); text.setTextSize(30);

            Toast toast = new Toast(getApplicationContext());
            toast.setView(text);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.show();


        } else if(re2IsShowing) {

//swichボタン押した後、画像re2は表示されていないと判定させる re2IsShowing = false;

            re2.animate().alpha(0).setDuration(1000);
            re3.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Play ~", Toast.LENGTH_LONG) .show ();

        } else {

            re1IsShowing = true;
            re2IsShowing = true;


            re3.animate().alpha(0).setDuration(1000);
            re1.animate().alpha(1).setDuration(1000);

Toast.makeText (this, "Do you look good?", Toast.LENGTH_LONG) .show (); }

    }




}

}

What should I do.

https://akira-watson.com/android/toast-custom.html [Android] Customize Toast

The article seems to be helpful, but I think I should give up because it seems complicated and I can not understand it.

Recommended Posts

Android Studio memo that you want to display Toast characters in large size
When you want to implement Java library testing in Spock with multi-module in Gradle in Android Studio 3
Source to display character array with numberPicker in Android studio (Java)
Java to C and C to Java in Android Studio
How to use ExpandableListView in Android Studio
3 ways to import the library in Android Studio
When you want to bind InputStream in JDBI3
[Ruby] When you want to replace multiple characters
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
[Android Studio] I want to use Maven library on Android
When you want to dynamically replace Annotation in Java8
If you want to recreate the instance in cloud9
Memo that transitions to the login screen if you are not logged in with devise
Notes in Android studio
Refer to C ++ in the Android Studio module (Java / kotlin)
Java study site summary that you want to read carefully
How to replace characters that you do not understand [Principle]
You are currently using Java 6. Solution in Android Studio Gradle
[Swift] When you want to know if the number of characters in a String matches a certain number ...
Object-oriented design that can be used when you want to return a response in form format