[英]Android Toast like pop up
我一直在使用Toast,但android是否有类似的功能,但是消息会一直显示直到用户将其关闭为止。
as per my knowledge you have three options to do this task. 据我所知,您有三种选择来完成此任务。
SnackBar 小吃店
CostumeToast CostumeToast
void errortoast(String Msg) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.custom_toast_layout)); TextView text = (TextView) layout.findViewById(R.id.textToShow); text.setText(Msg); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.TOP | 0, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); }
toast.xml toast.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@android:color/background_dark"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:id="@+id/textToShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_dialog_alert"
android:text="Error"
android:textColor="#FFFFFF"
android:textSize="19sp"/>
</LinearLayout>
PopUpWindow 弹出窗口
public void displaypopup() {
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(popupView, Gravity.TOP, 0, 0);
}
popup.xml popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lytpopup"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<TextView
android:id="@+id/tvmessagedialogtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center_horizontal"
android:text="Hello" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/bmessageDialogYes"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#cb4c4c"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:text="View"
android:textColor="#FFFFFF"
android:textSize="18dip" />
<Button
android:id="@+id/dismiss"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#77aa5c"
android:minHeight="0dp"
android:minWidth="0dp"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:text="Dismiss"
android:textColor="#FFFFFF"
android:textSize="18dip"
android:textStyle="normal"
android:typeface="normal" />
</LinearLayout>
For more information read 有关更多信息, 请阅读
You can use Dialog. 您可以使用对话框。
Read this page. 阅读此页面。 http://developer.android.com/reference/android/app/Dialog.html
http://developer.android.com/reference/android/app/Dialog.html
You can try Android Crouton : 您可以尝试Android Crouton:
Crouton is a class that can be used by Android developers that feel the need for an alternative to the Context insensitive Toast. Crouton是一类,可由需要上下文无关的Toast替代品的Android开发人员使用。
A Crouton will be displayed at the position the developer decides. 将在开发人员确定的位置显示一个Crouton。 Standard will be the top of an application window.
标准将是应用程序窗口的顶部。 You can line up multiple Croutons for display, that will be shown one after another.
您可以排列多个面包块进行显示,一个接一个地显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.