如何改变Android的敬酒
问题描述:
我使用的是Android敬酒的消息显示一条消息给用户,但即使当设置为_LENGTH_LONG时间似乎还不足以小吃吧。我想尝试SnackBar或任何其他显示方法,但我卡住了。我该如何申请?这是我的代码。如何改变Android的敬酒
@Override
protected void onPostExecute(String result) {
Toast toast = Toast.makeText(ctx, result, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 130);
toast.show();
}
我该如何将烤面包换成快餐栏或消息框等设置为显示更长时间,比如说1分钟?
答
非常相似:
import android.support.design.widget.Snackbar;
...
coordinatorLayout = (CoordinatorLayout) findViewById(R.id
.coordinatorLayout);
Snackbar snackbar = Snackbar.make(coordinatorLayout, "MESSAGE", Snackbar.LENGTH_LONG);
snackbar.show();
+0
关注我们: http://www.androidhive.info/2015/09/android-material-design-snackbar-example/ –
答
尝试。
String message;
int color;
message = "hello";
color = Color.RED;
Snackbar snackbar = Snackbar.make(findViewById(R.id.btn), message, Snackbar.LENGTH_LONG);
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(color);
snackbar.show();
按钮b1 =(按钮)findViewById(R.id.btn);
答
做一个活动,并得到视图onCreate(bundle)
和定义AsyncTask
作为内部类,做这样的
@Override
protected void onPostExecute(String result) {
// check view is not null
if(view!=null){
int durationInMills=60000;//your duration
String msg="Your Message";
Snackbar.make(view,msg,durationInMills).show();
}
}
试试这个:http://www.androidhive.info/2015/09/android-material -design-snackbar-example/ –