-2

I followed this or this to Show Alert dialog Message at Center. Actually, It Should Be work Fine.

AlertDialog.Builder ad= new AlertDialog.Builder(this);
TextView myMsg = new TextView(this);
myMsg.setText("This is new Custom Alert \n And \n Welcome to android");
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
ad.setView(myMsg);

But its showing Error at Gravity like, error: cannot find symbol variable Gravity

Can Any One Suggest me on this kind... it not even Compiling in New Android Studio.

ravi
  • 474
  • 1
  • 3
  • 11

2 Answers2

2

In your class add this line with other imports like so

import android.view.Gravity 

You can find more details on this official documentation page here

udit7395
  • 626
  • 5
  • 16
0
setGravity(Gravity.CENTER_HORIZONTAL);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
student
  • 27
  • 6
  • 5
    It's good practice on Stack Overflow to add an explanation as to why your solution should work. For more information read [How To Answer](//stackoverflow.com/help/how-to-answer). – Samuel Liew Apr 05 '18 at 12:18