Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

639
Views
Toast.setGravity() no funciona en mi AVD Nexus 6 API 30

Establecí la gravedad de mi tostada para que se muestre en la parte superior de la pantalla, con el siguiente código:

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

no funciona en mi AVD Nexus 6 API 30 con mensaje de LogCat:

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

sin embargo, parece estar bien cuando instalo el apk en mi teléfono Nokia X6 con Android 9. ¡Por favor, ayúdenme!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Como se dijo en la documentación de Android sobre el método Toast setGravity , este método ya no funciona para dispositivos que ejecutan API30 o superior. Supongo que tiene targetSdk establecido en 30 para su proyecto.

Advertencia: a partir de Android Build.VERSION_CODES#R, para las aplicaciones que tienen como objetivo el nivel de API Build.VERSION_CODES#R o superior, este método no es operativo cuando se lo llama en notificaciones de texto.

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

over 4 years ago · Santiago Trujillo Report

0

Los brindis de texto ya no se pueden personalizar. Deberá crear un brindis simple para personalizarlo. También deberá agregar el texto de su mensaje a un archivo Ver separado.

 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 Report

0

Si aún desea configurar la gravedad en Toasts en Android 11 y superior, consulte este artículo .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!