Android 4.0 Custom Dialog - possible Bug? - java

I am creating a custom Dialog with the following style:
<style name="FullHeightDialog" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
I put the following construction of the dialog:
public CustomDialog(Context context) {
super(context, R.style.FullHeightDialog);
setContentView(R.layout.custom_dialog_layout);
}
The custom_dialog_layout root is RelativeLayout with layout_margin="20dp", and inside I put LinearLayout with 3 simple Buttons.
I expect that the Dialog stretches to the full height and to the content width, in this case the LinearLayout with the 3 buttons.
It works fine on Android Gingerbread, BUT on Android 4, it never stretches more than ~40% of the screen.
On Android 4, I have to programatically set:
LayoutParams params = getWindow().getAttributes();
params.width = LayoutParams.MATCH_PARENT;
To make it work as expected. Even then, it shows non expected results, but nontheless, acceptable.
Is this a Bug of Ice Cream Sandwich or I am doing something wrong?

your problem might come from android:style/Theme.Dialog since it can evolve depending on android version.
solutions :
Define fully your own style with no reference to android:style/Theme.Dialog
refers to android:style/Theme.Dialog but add margins/paddings layout definitions in your style items

Related

Adding components programmatically has different style than those in XML layout

Components (text and edit boxes) defined in layout XML looks very different from those i add programatically.
I've tried to apply the same textAppearance style programatically as the ones from my XML has. I tried calling setTheme() after adding the components too. No difference.
TextView tv10 = new TextView(getApplicationContext());
tv10.setText("Back width");
EditText tv11 = new EditText(getApplicationContext());
tv11.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_CLASS_NUMBER);
TextView comes out with small font and gray text, EditText comes out with black background and gray text.
The components must be added programmatically because of options the user choose. Those user choices are defined in the XML and follow the expected color scheme, which is the Android Studio defaults. (Black text on white background)
You shouldn't use Application Context for views. Only Activity context. Also you can pass style as parameter, when create view in code.
As Yamko said, style can be passed in the constuctor
var textView = TextView(context, null, R.style.LoginBodyTextViewStyle)
where the style can be something like
<style name="LoginBodyTextViewStyle" parent="android:Widget.TextView">
<item name="android:textStyle">normal</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">#dimen/text_size_default</item>
<item name="android:textColor">#color/grey</item>
</style>

Android - how to disable / change editTexts 'Pin'

How can I edit or disable the 'pin' for editTexts that appears when marking text? I was able to edit the underline & the cursor, but not that 'pin' because I didn't know how to call it.
Image of the pin (pink) added.
I think the colourAccent influences the colour of that pin, try changing the colour of colourAccent in color.xml
This 'pin' is called "text select handle"
To change it you need to use these attributes:
text_select_handle_left and text_select_handle_right
Add these drawables with customized design/color to your drawable folder and add to style
<style name="MyTheme" parent="#style/MyCustomTheme">
<item name="android:textSelectHandle">#drawable/text_select_handle_middle</item>
<item name="android:textSelectHandleLeft">#drawable/text_select_handle_left</item>
<item name="android:textSelectHandleRight">#drawable/text_select_handle_right</item>
</style>

how to set live wallpaper for background of layout,image view or ... is that possible?

Hi all i want to know how to set background of layout,image view or ... to live wallpaper from java is that possible?how??
pick a live wallpaper and set that for background??we can do it with normal wallpaper with but i don't know about live wallpaper!
i tried Google search for long time.
i really need to know it.
this is for normal Drawable:
File backgroundf = new File(Uri.parse("sdcar/Wallpaper_BG.jpg").getPath());
if (backgroundf != null) {
Bitmap BarbackgroundBitmap = BitmapFactory.decodeFile(backgroundf.getAbsolutePath());
BackgroundDrawable = new BitmapDrawable(mContext.getResources(), backgroundBitmap);
}
mBackground.setImageDrawable(BarBackgroundDrawable);
Thanks.
You can't do this as a drawable or a view background, but you can theme your activity to make the wallpaper or live wallpaper show through.
<style name="MyTheme" parent="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowShowWallpaper">true</item>
</style>
You can use any theme as the parent. Put this in your styles resource and set this theme for the activity in the manifest.

Android Theme in APIDemos sample

I looked at the APIDemos examples for Android 4.2. All listView's items are seperated by a white line.
I created a simple project (Android 4.2), and changed style.xml to (instead of Theme.Light):
<style name="Theme" parent="android:Theme"> </style>
It displays the black background, but there is no white seperator line. I can not get the point how it set in APIDemos sample. could you help me?
I added <item name="android:divider" >#android:color/white</item>
but it does not work for the listView.
And this is my listView:
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);
Did you change the Theme in your Manifest?
Another possibility to customize a list is to define a ListView as an XML (my_list.xml). There you can add the attribut "android:divider". If you are working with fragments you can also call getListView in your onCreateView() after you inflating your my_list.xml.

Change the Dialog style using a theme

I was wondering whether there is a simple way to tell Android to always use a custom style to display Dialogs.
Using themes and styles you can change the look and feel of all, say, TextViews using this piece of code when defining a theme in themes.xml:
<item name="android:textViewStyle">#style/Blue.TextView</item>
with Blue.TextView being defined in styles.xml.
Is there some way to do so for Dialogs as well ?
yes, there is. for example,
AlertDialog.Builder b = new AlertDialog.Builder(context, R.style.MyTheme);
or, if you are using a DialogFragment, just call the setStyle() method,
<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item
name="android:windowBackground">#null</item>
</style>
Below is the working code::
Dialog mDialog = new Dialog(this,R.style.ThemeDialogCustom);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setCanceledOnTouchOutside(true); //But here It is not workin
mDialog.setContentView(R.layout.popup);

Categories