Android 实现类似Gmail的功能;“无连接”;在屏幕底部发出警报
下面是Gmail无连接警报。我将如何在我的应用程序中实现这一点 注意:这是一个关于UI实现的问题,而不是确定是否存在连接 编辑::Android 实现类似Gmail的功能;“无连接”;在屏幕底部发出警报,android,user-interface,gmail,Android,User Interface,Gmail,下面是Gmail无连接警报。我将如何在我的应用程序中实现这一点 注意:这是一个关于UI实现的问题,而不是确定是否存在连接 编辑:: 底部通知是以对话框为主题并放置在底部的活动,还是某种AlertDialog 我不确定谷歌是否就是这样实现他们的对话的,但这是我的建议。我创建了一个类,在清单中将其样式设置为对话框。因此,当我需要显示警报时,我只需启动意图并显示它。在活动中,我有一个PostDelayed处理程序,taht将等待3.5秒,然后结束活动,给出一个类似toast的动画(类似于Gmail:-
底部通知是以对话框为主题并放置在底部的活动,还是某种AlertDialog 我不确定谷歌是否就是这样实现他们的对话的,但这是我的建议。我创建了一个类,在清单中将其样式设置为对话框。因此,当我需要显示警报时,我只需启动意图并显示它。在活动中,我有一个PostDelayed处理程序,taht将等待3.5秒,然后结束活动,给出一个类似toast的动画(类似于Gmail:-) 找到下面的代码
static final int EXIT_DELAY= 3500;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.layout_pesabox_alert);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = 5;
params.height = 150;
params.width = 700;
params.y = 5;
params.gravity = Gravity.BOTTOM;
this.getWindow().setAttributes(params);
Window window = this.getWindow();
window.setAttributes((android.view.WindowManager.LayoutParams) params);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
new Handler().postDelayed(Exit(), EXIT_DELAY);
}
private Runnable Exit(){
return new Runnable(){
@Override
public void run() {
finish();
}
};
}
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/detailsText"
android:layout_width="wrap_content"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_dialog_alert"
android:drawablePadding="25dp"
android:text="@string/connection"
android:textColor="#ffffff"
android:textSize="25sp"
android:typeface="sans" />
</LinearLayout>
也许这个例子可以帮助你 编辑2: 材料设计也有课 编辑1: 好的,这个想法是在前面调用对话活动。为此: 1-创建alertbox_activity.xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#8A8A8A">
<TextView
android:id="@+id/alertbox_message"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:background="#8A8A8A"
android:textSize="20sp"
android:typeface="sans"
android:gravity="center" />
</LinearLayout>
3-将这些行添加到manifest.xml中
<activity
android:name="com.package.AlertBoxActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Dialog">
<intent-filter>
<action android:name="android.intent.action.ALERT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
完成。这是一篇非常古老的帖子,但如果其他人正在寻找谷歌式的“底部吐司式通知”。提到它也可以在支持库中找到。这篇文章很好地解释了如何使用向后兼容的Snackbar。这是一个相当普遍的问题…我已经给出了一个编辑…我意识到它的模糊性…我想获得一个类似于Gmail应用程序上面所示的alertdialog(如果有的话)。这是一个Snackbar-
<activity
android:name="com.package.AlertBoxActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Dialog">
<intent-filter>
<action android:name="android.intent.action.ALERT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Intent i = new Intent("android.intent.action.ALERT");
i.putExtra(AlertBoxActivity.KEY_BUNDLE_MESSAGE_TEXT, "YOUR ALERT GOES HERE!");
i.putExtra(AlertBoxActivity.KEY_BUNDLE_PARENT_WIDTH, getWindow().getAttributes().width);
startActivity(i);