1

Im showing a popup alert activity, when select a notification from tray. But on top it's showing the App name (MCP), with improper alignment.

Screenshot

I don't want the top part, just a normal dialog.

Manifest:

<activity
    android:name=".activity.AlertDialogActivity"
    android:configChanges="orientation|locale|screenSize|uiMode|fontScale"
    android:excludeFromRecents="true"
    android:theme="@style/AlertDialogTheme" />

Style:

<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog">
    <item name="android:windowNoTitle">true</item>
</style>

Alert 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();
        }
    });
}

Layout:

<?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>`

Also tried:

requestWindowFeature(Window.FEATURE_NO_TITLE);

and:

getWindow().setFeatureDrawableResource(Window.FEATURE_NO_TITLE, android.R.drawable.ic_dialog_alert)

before setContentView()

rekire
  • 47,260
  • 30
  • 167
  • 264
Abu Ruqaiyah
  • 1,516
  • 1
  • 12
  • 20
  • Did you try without the `android:` prefix, as follows: `name="windowNoTitle"`? – Blo Nov 05 '15 at 10:43
  • I did now and it worked, can you please explain the difference? – Abu Ruqaiyah Nov 05 '15 at 13:23
  • It's regarding your api level: "Due to limitations in Android's theming system any theme customizations must be declared in two attributes: the normal `android-`prefixed attributes apply the theme to the native style (API +1) and the unprefixed attributes are for the custom implementation (API +11)". See [this answer](http://stackoverflow.com/q/14154392/2668136) for more precisions (for ABS, but it's the same with AppCompat). – Blo Nov 05 '15 at 14:00

4 Answers4

2

Just Add Following code in style.xml
<item name="windowNoTitle">true</item> <item name="windowActionBar">false</item>

or You can hide it Programmatically.

getSupportActionBar().hide();

  • First item worked. As artman and Fllo mentioned, no need to put 'android'. 'getSupportActionBar().hide()' got NullPointerException. – Abu Ruqaiyah Nov 05 '15 at 13:22
1

Try this code (without using "android:")

<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Dialog">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
artman
  • 632
  • 2
  • 7
  • 16
1

I used this:

In AppCompatActivity onCreate() add following code:

setTitle("")

and Add The following code in 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>
Better
  • 165
  • 1
  • 13
0

Add requestWindowFeature in this way may be work proper.

First Call Super after add it.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.add__favourite_layout);
}
Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39