Vyacheslav Orlovsky
Vyacheslav Orlovsky

Reputation: 436

Action bar looks cut while using Theme.AppCompat.Dialog

I wished to make one of my activities to look like a dialog and used a Theme.AppCompat.Dialog theme for it, but it made it's action bar to look bad (see below).

Now background is cut to the length of the title string and I cant't find any theme property to fix it.(

What can be done to avoid it?

Related part of styles.xml:

<style name="DeviceListTheme" parent="Theme.AppCompat.Dialog">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

I start the activity using the following code:

Intent intent = new Intent(this, DeviceListActivity.class);
startActivityForResult(intent, REQUEST_CONNECT_DEVICE);

Upvotes: 5

Views: 5941

Answers (4)

Keshav Gera
Keshav Gera

Reputation: 11264

enter image description here

Its Working

<style name="AppThemeDialog" parent="Theme.AppCompat.Light.Dialog">
       <item name="android:windowNoTitle">true</item>
       <item name="android:spinnerStyle">@style/holoSpinner</item>
</style>

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_search);
       setTitle("Batches");
   }

Upvotes: 0

Anton
Anton

Reputation: 570

I solved the same problem this way:

Activity:

public class MyActivity extends android.support.v4.app.FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_layout);
        setTitle("View task");
    }
}

Theme:

<style name="Theme.MyDialog" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">false</item>
</style>

Manifest:

<activity android:name=".MyActivity" android:theme="@style/Theme.MyDialog"/>

Result:

Upvotes: 0

Vitaliy L
Vitaliy L

Reputation: 581

Use DialogWhenLarge instead of standard Dialog style:

<style name="MyDialogTheme" parent="@style/Theme.AppCompat.Light.DialogWhenLarge">
...
</style>

Upvotes: 0

Farbod Salamat-Zadeh
Farbod Salamat-Zadeh

Reputation: 20140

First, when I encountered this problem, I tried using supportRequestWindowFeature(Window.FEATURE_NO_TITLE); but this didn't work for me and had no effect.

The alternative method to remove the bar at the top of your dialog activity would be to create a custom style and apply it to that activity.

In styles.xml, create a new style like so:

<style name="MyCustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

Now, in AndroidManifest.xml, add in android:theme="@style/MyCustomDialog" to your activity.

Of course, MyCustomDialog can be renamed to anything you want.

Upvotes: 4

Related Questions