-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the bug that button text overflow when the device is over lollipop.
- Loading branch information
Shintaro Katafuchi
committed
Jun 28, 2015
1 parent
45cbdad
commit 38da532
Showing
3 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package hotchemi.android.rate; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.app.AlertDialog; | ||
import android.content.Context; | ||
import android.os.Build; | ||
|
||
final class Utils { | ||
|
||
private Utils() { | ||
} | ||
|
||
static boolean underHoneyComb() { | ||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB; | ||
} | ||
|
||
static boolean overLollipop() { | ||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; | ||
} | ||
|
||
static int getDialogTheme() { | ||
return overLollipop() ? R.style.CustomLollipopDialogStyle : 0; | ||
} | ||
|
||
@SuppressLint("NewApi") | ||
static AlertDialog.Builder getDialogBuilder(Context context) { | ||
if (underHoneyComb()) { | ||
return new AlertDialog.Builder(context); | ||
} else { | ||
return new AlertDialog.Builder(context, getDialogTheme()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="CustomLollipopDialogStyle" parent="android:Theme.Material.Light.Dialog.Alert"> | ||
<item name="android:buttonBarButtonStyle">@style/CustomButtonBarButtonStyle</item> | ||
<item name="android:buttonBarStyle">@style/CustomButtonBarStyle</item> | ||
</style> | ||
|
||
<style name="CustomButtonBarStyle" parent="@android:style/Widget.Material.Light.ButtonBar.AlertDialog"> | ||
<!-- Making sure, the button bar uses parent width and is not restricted in height --> | ||
<item name="android:layout_width">match_parent</item> | ||
<item name="android:layout_height">wrap_content</item> | ||
<item name="android:height">@null</item> | ||
<item name="android:minHeight">@null</item> | ||
</style> | ||
|
||
<style name="CustomButtonBarButtonStyle" parent="@android:style/Widget.Material.Light.Button.Borderless.Colored"> | ||
<!-- Setting the weight as follows should result in equally wide buttons filling the alert dialog width, | ||
but instead they span further out of the dialog, breaking in multiple lines though --> | ||
<item name="android:layout_width">0dp</item> | ||
<item name="android:layout_weight">1</item> | ||
<!-- TODO: setting a fixed width as follows results in narrow buttons with line breaks, but of course this is not a solution --> | ||
<item name="android:width">100dp</item> | ||
</style> | ||
|
||
</resources> |