Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

640
Visualizações
Toast.setGravity() does not work in my AVD Nexus 6 API 30

I set the gravity of my toast to make it show on the top of the screen, with code below:

Toast toast = Toast.makeText(getActivity(), "邮箱地址不能为空!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();

it does not work in my AVD Nexus 6 API 30 with LogCat message:

E/Toast: setGravity() shouldn't be called on text toasts, the values won't be used

however it seems fine when I install the apk on my phone Nokia X6 with Android 9. please help me!!

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

As it said in Android documentation about Toast setGravity method, this method doesn't work anymore for devices running API30 or higher. I suppose you have targetSdk set to 30 for your project.

Warning: Starting from Android Build.VERSION_CODES#R, for apps targeting API level Build.VERSION_CODES#R or higher, this method is a no-op when called on text toasts.

SOURCE: https://developer.android.com/reference/android/widget/Toast#setGravity(int,%20int,%20int)

over 4 years ago · Santiago Trujillo Relatório

0

Text Toasts can no longer be customized. You'll need to create a simple Toast in order to customize. You will also need to add your message text to a separate View file.

        Toast toast = new Toast(getContext());
        View toast_view = LayoutInflater.from(getContext()).inflate(R.layout.toast_text, null);
        toast.setView(toast_view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
over 4 years ago · Santiago Trujillo Relatório

0

If you still want to set the gravity on Toasts on Android 11 and above, see this article.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda