android 设置断网界面,No Internet Dialog 一个用于提示断网的漂亮Android对话框

No Internet Dialog

A beautiful Dialog which appears when you have lost your Internet connection.

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d4e6f253230496e7465726e65742532304469616c6f672d79656c6c6f772e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f62616467652f4150492d31342532422d79656c6c6f772e7376673f7374796c653d666c61742d737175617265

Setup

Gradle:

Add following line of code to your module(app) level gradle file

implementation 'am.appwise.components:NoInternetDialog:1.1.3'

Maven:

am.appwise.components

NoInternetDialog

1.1.3

pom

Usage

Use simple builder to initiate the dialog. It will automatically appear if you'll lose your Internet connection, and dissapear, once it came back

NoInternetDialog noInternetDialog = new NoInternetDialog.Builder(context).build();

or

NoInternetDialog noInternetDialog = new NoInternetDialog.Builder(fragment).build();

and at the end

@Override

protected void onDestroy() {

super.onDestroy();

noInternetDialog.onDestroy();

}

Customize the dialog with ease

builder.setBgGradientStart() // Start color for background gradient

builder.setBgGradientCenter() // Center color for background gradient

builder.setBgGradientEnd() // End color for background gradient

builder.setBgGradientOrientation() // Background gradient orientation (possible values see below)

builder.setBgGradientType() // Type of background gradient (possible values see below)

builder.setDialogRadius() // Set custom radius for background gradient

builder.setTitleTypeface() // Set custom typeface for title text

builder.setMessageTypeface() // Set custom typeface for message text

builder.setButtonColor() // Set custom color for dialog buttons

builder.setButtonTextColor() // Set custom text color for dialog buttons

builder.setButtonIconsColor() // Set custom color for icons of dialog buttons

builder.setWifiLoaderColor() // Set custom color for wifi loader

builder.setConnectionCallback() // Set a Callback for network status

builder.setCancelable(false) // Set cancelable status for dialog

f21ec2039a2211c4bbe507472941be57.png

9249048dca88ef7add550fc7079241ad.png

ff17aef0e20330408d5f9bc4568fc70c.gif

ninm.gif

This is work is is inspired from the work of Ramakrishna V. in Dribbble.

Versions

1.1.3

Connection callback status added Cancelable flag added

1.1.2

Receivers issue fixed

1.1.1

Vector drawable issue fixed for < API 21 UI issues fixed for small devices

1.1.0

New customization features added Issues fixed

1.0.1

Appear issue fixed

1.0.0

First version of library

Licence

No Internet Dialog©

Copyright 2017 Appwise

Url: https://github.com/appwise-labs/NoInternetDialog

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 您可以按照以下步骤在 Android 中实现一个按钮点击后弹出删除对话框: 1. 在您的布局文件中添加一个按钮,例如: ``` <Button android:id="@+id/delete_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Delete" /> ``` 2. 在您的 Activity 或 Fragment 中找到该按钮并为其设置一个点击事件监听器,例如: ``` Button deleteButton = findViewById(R.id.delete_button); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 弹出删除对话框 showDeleteDialog(); } }); ``` 3. 编写一个方法 `showDeleteDialog()` 来显示删除对话框,例如: ``` private void showDeleteDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Delete Item") .setMessage("Are you sure you want to delete this item?") .setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 在这里执行删除操作 } }) .setNegativeButton("Cancel", null) .show(); } ``` 4. 在对话框的确认按钮的点击事件中添加您需要执行的删除操作。 这样,当用户点击删除按钮后,将会弹出一个删除对话框,询问用户是否确认删除,如果确认删除,则执行您编写的删除操作。如果用户选择取消,则对话框会关闭而不执行任何操作。 ### 回答2: 在Android中点击一个按钮跳出删除对话框,可以按照以下步骤实现: 首先,需要在布局文件中定义一个按钮。可以使用Button或者ImageButton控件,并设置相应的属性,如id和点击事件等。 接下来,在Java代码中找到这个按钮,并为其设置OnClick事件监听器。在点击事件的回调函数中,可以执行一系列操作,包括跳出删除对话框的操作。 在OnClick事件回调函数中,可以使用AlertDialog类来创建一个删除对话框。可以使用AlertDialog.Builder类来构建对话框的内容和样式。使用它的setTitle方法设置对话框的标题,setMessage方法设置对话框的消息内容,以及setPositiveButton和setNegativeButton方法来设置对话框的确认和取消按钮。 代码示例如下: 按钮的布局文件: <Button android:id="@+id/deleteButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" android:onClick="showDeleteDialog" /> Java代码: public class MainActivity extends AppCompatActivity { private Button deleteButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); deleteButton = findViewById(R.id.deleteButton); } public void showDeleteDialog(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("删除对话框") .setMessage("确定要删除吗?") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 确定按钮点击事件的处理逻辑 } }) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 取消按钮点击事件的处理逻辑 } }) .show(); } } 以上就是在Android中点击一个按钮跳出删除对话框的实现方法。根据实际需求,可以自定义对话框的样式和操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值