<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:text="显示通知"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:onClick="show1" />
</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
}
public void show1(View v){
View inflate = View.inflate(MainActivity.this, R.layout.a, null);
View viewById = inflate.findViewById(R.id.buttons);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(inflate);
final AlertDialog alertDialog = builder.create();
viewById.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
down();
}
});
alertDialog.show();
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="正在下载"
android:textColor="#000"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ss"
android:text="dddd"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/buttons"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke
android:width="0.8dp"
android:color="#ffffff" />
<!-- 圆角 -->
<corners android:radius="6dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DialogTheme" parent="android:style/Theme.Dialog">
<!--是否浮现在activity之上-->
<item name="android:windowIsFloating">true</item>
</style>
<style name="DialogTheme.Transparent" parent="DialogTheme">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="DialogTheme.Transparent.NoTitle" parent="DialogTheme.Transparent">
<item name="android:windowNoTitle">true</item>
</style>
<style name="DialogTheme.MyDialog" parent="DialogTheme.Transparent.NoTitle">
<!--是否模糊-->
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>