我尝试了很多主题以徒劳地将活动更改为警报对话框。之前,我记得完成,但不能现在就做无法将活动更改为AlertDialog
这里的应用程序的主题:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/background</item>
</style>
这里的活动,我想变成一个警告对话框:
实时活动包含比这更多(按钮,线性布局,文本视图)。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.famiddle.android.thechanakyanitiplus.NotificationCenter">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/notification_center_title"
android:gravity="center_horizontal"
android:textColor="@color/colorAccent"
android:layout_marginTop="8dp" />
</ScrollView>
它的Java文件(NotificationCenter.java)
public class NotificationCenter extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// To remove status bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_notification_center);}}
按钮,将开始本次活动:
LinearLayout notificationManager = (LinearLayout) findViewById(R.id.notification_manager);
notificationManager.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), NotificationCenter.class));
}
});
最后,AndroidManifest文件:
<activity
android:name=".NotificationCenter"
android:theme="@style/Theme.AppCompat.Dialog"
android:excludeFromRecents="true">
</activity>
我已经尝试了不同的主题在这里提到Android Activity as a dialog,但每当我点击按钮,它有点崩溃的应用程序(重新启动它)。
感谢,@Arpit尔斯基它的工作。 –