从托盘中选择通知时,显示弹出警报活动。 但是最上面显示的是应用程序名称(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”'? – Fllo
我现在做了,它的工作,你能解释一下这个区别吗? –
这是关于你的api级别的:“由于Android的主题系统的限制,任何主题自定义都必须声明为两个属性:普通的'android-'预置属性将主题应用于本地样式(API +1),而前缀不变的属性对于自定义实现(API +11)“。请参阅[本答案](http://stackoverflow.com/q/14154392/2668136)以获取更多精确度(对于ABS,但它与AppCompat相同)。 – Fllo