I read many topics, but I didn't find answer of my problem. I'm trying to use android.R.style.Theme_Translucent_NoTitleBar or xml styles with
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#color/transparent_white</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>
Even I have added
dialog.getWindow().setBackgroundDrawableResource(R.drawable.pixel);
where pixel is transparent drawable, but with no luck. I always have white border.
My code is below:
Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.pixel);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ListView modeList = new ListView(this);
String[] stringArray = new String[] { "aaa", "bbb" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
stringArray);
modeList.setAdapter(modeAdapter);
builder.setView(modeList);
dialog = builder.create();
Regards,
Swierzy
The white border of a dialog is a 9patch image
and your background picture has to be an 9patch picture.
http://developer.android.com/guide/developing/tools/draw9patch.html
You can draw it yourself and make any border you like there.
you create your dialog like that
public AboutDialog(Context context) {
super(context,R.style.Theme_Dialog);
.......
and your style e.g.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.Dialog" parent="Theme">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/bg</item> <------- your 9patch background picture
</style>
hope this helps abit
Related
I am creating a custom spinner at runtime. after running the application the spinner style has successfully changed, but there are no more drop down when I click on the spinner. Any help would be appreciated.
Code in styles.xml
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="#attr/spinner_style">#style/spinner_style</item>
</style>
<style name="spinner_style" parent="#android:style/Theme.Holo.Light">
<item name="android:background">#drawable/gradiant_spinner</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:popupBackground">#DFFFFFFF</item>
</style>
in attr.xml
<?xml version="1.0" encoding="utf-8"?>
<resources> <attr name="spinner_style" format="reference"/></resources>
in MyCustomSpinner:
public class MyCustomSpinner extends Spinner
{
public MyCustomSpinner(Context context) {
super(context, null, R.attr.spinner_style);
}
}
in Activity:
final MyCustomSpinner spinner = new MyCustomSpinner(context); //INITIALIZE THE SPINNER
spinner.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, lookupValues));
Try this:
final MyCustomSpinner spinner = new MyCustomSpinner(context);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter, lookupValues));
adapter.notifyDataSetChanged();
if it don't work try to the keyword "final" before MyCustomSpinner spinner = ..
I am trying new AlertDialog from appcompat v7 22.1.1.
It works pretty well (In all android versions) as in image.
Style for AlertDialog is this. (For now I am using hardcoded color values instead of color resources)
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#111111</item>
<item name="colorPrimary">#00ddff</item>
<item name="colorAccent">#0044aa</item>
<item name="colorButtonNormal">#00aaaa</item>
<item name="colorControlHighlight">#00ddff</item>
<item name="alertDialogTheme">#style/AlertDialogTheme</item>
</style>
<style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorAccent">#0044aa</item>
<item name="android:background">#ffffff</item>
<item name="android:textColorPrimary">#000000</item>
<item name="android:windowTitleStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTitleTextStyle">
<item name="android:textColor">#0044aa</item>
<item name="android:textAppearance">#style/TextAppearance.AppCompat.Title</item>
</style>
My question is ,
1) how to change statePressed color which is rounded (Gray) in the image ?
2) No pressed color is there in android >= 21 , what is hack for this ?
3) How can I have different colors of action buttons (Is it possible)?
Any help would be great.
You can use style attributes like
buttonBarButtonStyle
buttonBarNegativeButtonStyle
buttonBarNeutralButtonStyle
buttonBarPositiveButtonStyle
Example:
<style name="dialog_theme" parent="Theme.AppCompat.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">#style/dialog_button.negative</item>
<item name="buttonBarPositiveButtonStyle">#style/dialog_button.positive</item>
</style>
<style name="dialog_button">
<item name="android:textStyle">bold</item>
<item name="android:minWidth">64dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:background">#drawable/dialogButtonSelector</item>
</style>
<style name="dialog_button.negative">
<item name="android:textColor">#f00</item>
</style>
<style name="dialog_button.positive">
<item name="android:layout_marginLeft">8dp</item>
<item name="android:textColor">#00f</item>
</style>
Where dialogButtonSelector is our custom drawable selector.
Unfortunatelly setting background on dialog_button destroy our paddings and margins so I need to set it again.
dialog_button style can inherit through Widget.AppCompat.Button.ButtonBar.AlertDialog but I found that it has missing styles like textStyle bold.
I have the Answer for the 3rd Questions
( How can I have different colors of action buttons (Is it possible)? )
Code:
// Initialize AlertDialog & AlertDialog Builder
AlertDialog.Builder builder = new AlertDialog.Builder(YourActivity.this);
builder.setTitle("AlertDialog Title");
...........
.........
//Build your AlertDialog
AlertDialog Demo_alertDialog= builder.create();
Demo_alertDialog.show();
//For Positive Button:
Button b_pos;
b_pos=Demo_alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if(b_pos!=null){
b_pos.setTextColor(getResources().getColor(R.color.YourColor));
}
//For Neutral Button:
Button b_neu;
b_neu=Demo_alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL);
if(b_neu!=null){
b_neu.setTextColor(getResources().getColor(R.color.YourColor));
}
//For Negative Button:
Button b_neg;
b_neg=Demo_alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
if(b_neg!=null){
b_neg.setTextColor(getResources().getColor(R.color.YourColor));
}
Happy Coding :)
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage("Title"); builder.setCancelable(true);
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertdialog = builder.create();
alertdialog.show();
Button nbutton = alertdialog.getButton(DialogInterface.BUTTON_NEGATIVE);
nbutton.setBackground(getResources().getDrawable(R.drawable.btn_press_white_rect));
Button pbutton = alertdialog.getButton(DialogInterface.BUTTON_POSITIVE);
pbutton.setBackground(getResources().getDrawable(R.drawable.btn_press_white_rect));
**btn_press_white_rect.xml**
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/rounded_rect_yellow" ></item>
<item android:state_pressed="false" android:drawable="#drawable/rounded_rect_white" ></item>
</selector>
I'm creating an alert dialog this way:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(view.getContext());
alertDialog.setCustomTitle(null);
alertDialog.setItems(getAllListNames(), new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
//Doing something awesome...
}
});
I know it creates a list view with my items, I want to set a typeface with a custom font for them and also set a max number of characters for each list item, how can I do it?
You have to create a custom theme. Here is the official guide: http://developer.android.com/guide/topics/ui/themes.html :)
Something like this (in the style.xml file):
<style name="CustomFontTheme" parent="android:Theme.Light">
<item name="android:textViewStyle">#style/MyTextViewStyle</item>
<item name="android:buttonStyle">#style/MyButtonStyle</item>
</style>
<style name="MyTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="MyButtonStyle" parent="android:Widget.Holo.Button">
<item name="android:fontFamily">sans-serif-light</item>
</style>
Then when you create the dialog you can do this:
Context context = new ContextThemeWrapper(view.getContext(), R.style.CustomFontTheme)
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
Where R.style.CustomFontTheme is the id for the them you have created.
Update:
Ok, to add your custom typeface you can follow this gist:
https://gist.github.com/artem-zinnatullin/7749076
The key is to override the a given font face when the application starts like this:
TypefaceUtil.overrideFont(getApplicationContext(), "AWESOME-FONT", "fonts/Awesome-Font.ttf");
the gist has the implementation for that method.
So the theme styles should look like this now:
<style name="MyTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">awesome-font</item>
</style>
<style name="MyButtonStyle" parent="android:Widget.Holo.Button">
<item name="android:fontFamily">awesome-font</item>
</style>
I have an AlertDialog :
AlertDialog.Builder builder = new AlertDialog.Builder(context, AlertDialog.THEME_HOLO_LIGHT);
ListAdapter adapter = new CustomDialogAdapter(context, itemsList);
builder.setAdapter(adapter, listener);
builder.setTitle(title);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
setCanceledOnTouchOutside is working only when i tap on a certain distance from the dialog.When i tap just near the dialog it doesn't get dismissed.Do you guys know a way to dismiss the dialog even when i tap just near the dialog?Thanks.
Using AlertDialog.THEME_HOLO_LIGHT works if you want the dialog to be full screen. An alternative is to create your own style, like so:
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.ThemeDialogCustom);
ListAdapter adapter = new CustomDialogAdapter(context, itemsList);
builder.setAdapter(adapter, listener);
builder.setTitle(title);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
have style.xml in values folder like below:::
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ThemeDialogCustom" parent="android:Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowBackground">#color/transparent_color</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
</resources>
also add colors.xml in values folder:::
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent_color">#00000000</color>
</resources>
This is working for me. Hope it will works for you as well
How can I reduce the height of the green title?
Activity:
final Dialog dialog = new Dialog(EditorActivity.this, R.style.dialog);
dialog.setContentView(R.layout.preference_timerange);
dialog.setTitle(getString(R.string.zmien_czas_wyprawy));
Styles.xml
<style name="dialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/dialog_title_style</item>
<item name="android:windowBackground">#color/dialog_background</item>
<item name="android:textColor">#color/dialog_text</item>
</style>
<style name="dialog_title_style" parent="android:TextAppearance.WindowTitle">
<item name="android:textSize">16dp</item>
<item name="android:background">#color/dialog_title_background</item>
<item name="android:textColor">#color/dialog_title_text</item>
</style>
I don't know how to change the height of the Dialog's title, but you can remove the whole title and create a smaller one in your layout preference_timerange.xml:
final Dialog dialog = new Dialog(EditorActivity.this, R.style.dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.preference_timerange);
// Set R.string.zmien_czas_wyprawy as the title in your layout now