Android 中心的警报消息不起作用
Android Alert Message At Center not Working
我按照 this or this 在中心显示警报对话框消息。
实际上,它应该工作正常。
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);
但它显示重力误差,例如,
error: cannot find symbol variable Gravity
任何人都可以向我推荐这种类型的...它甚至不能在新 Android Studio 中编译。
在你的 class 中添加这一行与其他进口一样
import android.view.Gravity
您可以在此官方文档页面上找到更多详细信息here
setGravity(Gravity.CENTER_HORIZONTAL);
我按照 this or this 在中心显示警报对话框消息。 实际上,它应该工作正常。
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);
但它显示重力误差,例如,
error: cannot find symbol variable Gravity
任何人都可以向我推荐这种类型的...它甚至不能在新 Android Studio 中编译。
在你的 class 中添加这一行与其他进口一样
import android.view.Gravity
您可以在此官方文档页面上找到更多详细信息here
setGravity(Gravity.CENTER_HORIZONTAL);