应用程序名称显示在警报 Activity 弹出窗口顶部
App name showing on top of Alert Activity popup
当 select 来自托盘的通知时,我显示弹出式警报 activity。
但最上面显示的是 App 名称 (MCP),对齐方式不正确。
我不想要顶部的部分,只是一个普通的对话框。
清单:
<activity
android:name=".activity.AlertDialogActivity"
android:configChanges="orientation|locale|screenSize|uiMode|fontScale"
android:excludeFromRecents="true"
android:theme="@style/AlertDialogTheme" />
风格:
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
警报activity:
public class AlertDialogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert_dialog);
this.setFinishOnTouchOutside(false);
String message = getIntent().getExtras().getString("message");
TextView tvPushMessage = (TextView) findViewById(R.id.tvAlertMessage);
tvPushMessage.setText(message);
Button btnPushOk = (Button) findViewById(R.id.btnAlertOk);
btnPushOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/background_round_rectangle"
android:padding="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/tvAlertMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Message"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black" />;
<Button
android:id="@+id/btnAlertOk"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="@id/tvAlertMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@drawable/btn_use"
android:text="@string/ok"
android:textColor="@color/white" />
</RelativeLayout>`
也尝试过:
requestWindowFeature(Window.FEATURE_NO_TITLE);
和:
getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert)
在setContentView()
之前
只需在style.xml中添加以下代码即可
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
或者您可以通过编程隐藏它。
getSupportActionBar().hide();
试试这个代码(不使用 "android:")
<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
以这种方式添加 requestWindowFeature 可能会正常工作。
添加后先调用Super
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add__favourite_layout);
}
我用过这个:
在AppCompatActivity的onCreate()中添加如下代码:
setTitle("")
并在style.xml
中添加以下代码
<style name="PopupWindowTheme" parent="@style/Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/AnimBottom</item>
</style>
当 select 来自托盘的通知时,我显示弹出式警报 activity。 但最上面显示的是 App 名称 (MCP),对齐方式不正确。
我不想要顶部的部分,只是一个普通的对话框。
清单:
<activity
android:name=".activity.AlertDialogActivity"
android:configChanges="orientation|locale|screenSize|uiMode|fontScale"
android:excludeFromRecents="true"
android:theme="@style/AlertDialogTheme" />
风格:
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
警报activity:
public class AlertDialogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert_dialog);
this.setFinishOnTouchOutside(false);
String message = getIntent().getExtras().getString("message");
TextView tvPushMessage = (TextView) findViewById(R.id.tvAlertMessage);
tvPushMessage.setText(message);
Button btnPushOk = (Button) findViewById(R.id.btnAlertOk);
btnPushOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/background_round_rectangle"
android:padding="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/tvAlertMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Message"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black" />;
<Button
android:id="@+id/btnAlertOk"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="@id/tvAlertMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@drawable/btn_use"
android:text="@string/ok"
android:textColor="@color/white" />
</RelativeLayout>`
也尝试过:
requestWindowFeature(Window.FEATURE_NO_TITLE);
和:
getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert)
在setContentView()
只需在style.xml中添加以下代码即可
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
或者您可以通过编程隐藏它。
getSupportActionBar().hide();
试试这个代码(不使用 "android:")
<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
以这种方式添加 requestWindowFeature 可能会正常工作。
添加后先调用Super
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.add__favourite_layout);
}
我用过这个:
在AppCompatActivity的onCreate()中添加如下代码:
setTitle("")
并在style.xml
中添加以下代码<style name="PopupWindowTheme" parent="@style/Theme.AppCompat.Dialog.Alert">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/AnimBottom</item>
</style>