【发布时间】:2017-03-09 10:17:41
【问题描述】:
当从托盘中选择通知时,我会显示弹出警报活动。 但最重要的是它显示了应用程序名称 (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>
警报活动:
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()之前
【问题讨论】:
-
你试过不带
android:前缀吗,如下:name="windowNoTitle"? -
我现在做了,它成功了,你能解释一下区别吗?
-
这与您的 api 级别有关:“由于 Android 主题系统的限制,任何主题自定义都必须在两个属性中声明:普通的
android-prefixed 属性将主题应用于原生样式(API +1 ) 和无前缀属性用于自定义实现 (API +11)”。更多精度请参见this answer(对于 ABS,但与 AppCompat 相同)。
标签: android android-activity alert android-alertdialog