应用程序名称显示在警报活动弹出框
从托盘中选择通知时,显示弹出警报活动。 但是最上面显示的是应用程序名称(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()
只需添加以下代码style.xml <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item>
或者你可以将其隐藏临语法。
getSupportActionBar().hide();
第一项工作。正如Artman和Fllo提到的,不需要放置'android'。 “getSupportActionBar()。hide()'有NullPointerException。 –
试试这个代码(不使用 “机器人”)
<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
添加requestWindowFeature这种方式可能是适当的工作。
添加后第一次呼叫超级。
@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>
你不试试'android:'前缀,如下所示:'name =“windowNoTitle”'? – Fllo
我现在做了,它的工作,你能解释一下这个区别吗? –
这是关于你的api级别的:“由于Android的主题系统的限制,任何主题自定义都必须声明为两个属性:普通的'android-'预置属性将主题应用于本地样式(API +1),而前缀不变的属性对于自定义实现(API +11)“。请参阅[本答案](http://stackoverflow.com/q/14154392/2668136)以获取更多精确度(对于ABS,但它与AppCompat相同)。 – Fllo