Styling the DatePicker - android

I have been trying very hard to style the text size and colour on android 3.2. When attempting to override the default style with
<item name="android:numberPickerInputTextStyle">#style/numberPickerInputText</item>
I always get this error:
error: Error: No resource found that matches the given name: attr 'android:numberPickerInputTextStyle'.
Why is this so? I am pretty sure I selected the correct style to override (dug it from the platform 13 API folder)
I looked in these places.. seems like it cant be helped!
http://code.google.com/p/android/issues/detail?id=18659#c8
No resource found that matches the given name '#android:style/AlertDialog' error after the latest android 3.2 sdk update
This blog below said something about importing the styles into my application. How is it supposed to be done? examples?
http://daniel-codes.blogspot.com/2011/08/new-to-android-more-style-restrictions.html
Can someone please point me to the right direction? Thanks!

Quick and dirty way.. apply it after you show the dialog. Not a good solution but it works.. still looking for other solutions :)
//Should'nt be here but well..
public static void changeDialogTextSize(Dialog dialog) {
TextView tvMessage = (TextView)dialog.findViewById(android.R.id.message);
if (tvMessage != null)
{
tvMessage.setTextSize(25f);
tvMessage.setTextColor(Color.WHITE);
}
}

Related

Porting a Java SDK to Xamarin.Android, binding Library error regarding types

I am working on porting a Java SDK to Xamarin.Android.
After solving numerous errors, I am stuck in this one:
/Users/alejandro_l/Projects/KontaktBeaconSDK/KontaktBeaconSDK/obj/Debug/generated/src/Com.Kontakt.Sdk.Android.Ble.Configuration.Scan.EddystoneScanContext.cs(65,65): Error CS1715: Com.Kontakt.Sdk.Android.Ble.Configuration.Scan.EddystoneScanContext.EventTypes': type must beSystem.Collections.Generic.ICollection' to match overridden member `Com.Kontakt.Sdk.Android.Ble.Configuration.Scan.AbstractProfileSpecificScanContext.EventTypes' (CS1715) (KontaktBeaconSDK)
For solving the error I though that it should be OK to use the following line in the metadata.xml telling the generator to change the type of the method to match with the abstract class:
<attr path="/api/package[#name='com.kontakt.sdk.android.ble.configuration.scan']/class[#name='EddystoneScanContext']/method[#name='getEventTypes' and count(parameter)=0]" name="managedType">System.Collections.Generic.ICollection</attr>
Based on: https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/customizing-bindings/java-bindings-metadata/#managedType
The generated output still has the wrong shape:
static IntPtr id_getEventTypes;
public override unsafe global::System.Collections.ICollection EventTypes {
// Metadata.xml XPath method reference: path="/api/package[#name='com.kontakt.sdk.android.ble.configuration.scan']/class[#name='EddystoneScanContext']/method[#name='getEventTypes' and count(parameter)=0]"
[Register ("getEventTypes", "()Ljava/util/Collection;", "GetGetEventTypesHandler")]
get {
if (id_getEventTypes == IntPtr.Zero)
id_getEventTypes = JNIEnv.GetMethodID (class_ref, "getEventTypes", "()Ljava/util/Collection;");
try {
return global::Android.Runtime.JavaCollection.FromJniHandle (JNIEnv.CallObjectMethod (Handle, id_getEventTypes), JniHandleOwnership.TransferLocalRef);
} finally {
}
}
}
As you can see System.Collections.ICollection is generated and not System.Collections.Generic.ICollection.
Note: I even still did not figure it out how to also set the generic type, but that is the next step.
I am a newbie in binding and I cannot figure it out. Can someone tell me what I am doing wrong? Am I trying an impossible here? Do I need to change the source code of the SDK? (Notice that if I use "Build" and change manually the output I may get the dll in a future (still 49 errors left though) but I wonder if I can solve in a proper way).
Another useful link I used: https://gist.github.com/brendanzagaeski/9607158
Found it:
<attr path="/api/package[#name='com.kontakt.sdk.android.ble.configuration.scan']/class[#name='EddystoneScanContext']/method[#name='getEventTypes' and count(parameter)=0]" name="return">System.Collections.Generic.ICollection<Com.Kontakt.Sdk.Android.Ble.Discovery.EventType></attr>
It seems the error has disappeared due to name="return". I do not know why return does not appear in the documentations but it appears in the api.xml so it should be OK.

Why doesn't getResources().getIdentifier() work here (API level 22)?

Trying to change the appearance of the AlertDialog, I subclassed DialogFragment with ThemedDialogFragment and I called this lines onStart():
int alertTitleId = getResources().getIdentifier("alertTitle", "id", "android");
TextView alertTitle = (TextView) dialog.findViewById(alertTitleId);
alertTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen._20ssp));
That resulted in a NullPointerException, even though I am sure there is a view with id alertTitle in the window. The HierarchyViewer(*) tool confirms.
Tried to do minor variants
e.g.
int alertTitleId = getResources().getIdentifier("android:id/alertTitle", null, null);
or
TextView alertTitle = (TextView) dialog.getWindow().findViewById(alertTitleId);
or
TextView alertTitle = (TextView) dialog.getWindow().getDecorView().findViewById(alertTitleId);
but none of this works.
Any idea, guys?
(*): HierarchyViewer shows the id I'm looking for exists
P.S.: I solved the AlertDialog styling problem, by operating on the themes.xml, I just want to know why this method didn't work (it should IMO).
Having said so, I will downvote every answer that tells me how to style an AlertDialog because it's off-topic here. Thanks.
P.P.S: As a sidenote, I tried this method compiling agains the sdk level 22 and tested it on an Android emulator running Android Jelly Bean 4.3.1.
P.P.P.S: No luck on an emulator running 5.1.1 either.
It appears that you're trying to access an internal resource ID. In this case the package isn't "android" but "com.android.internal", but I'm not sure if even that would actually return the ID for you.
Android Dialog with modifiable single line title
Unfortunately, I cannot access their R.id.alertTitle, because it is part of com.android.internal.R.

Android svg parsing , official library issues

Hello im writing an android app using the android svg-android.jar. (I think it's the google official library) I'm trying to parse my svg im getting an error. my svg falls on this line :
<stop offset="0.1774" style="stop-color:#EDEDED;stop-opacity:0.2"/>
the error i get is this :
java.lang.NumberFormatException: Invalid int: "EDEDED;stop-opacity:0.2"
in the google code for the project i saw this :
if (gradient != null) {
float offset = getFloatAttr("offset", atts);
String style = getStringAttr("style", atts);
if (style.startsWith("stop-color:#")) {
int color = Integer.parseInt(style.substring("stop-color:#".length()), 16);
color |= 0xFF000000;
gradient.positions.add(offset);
gradient.colors.add(color);
}
}
it seems that google can't handle the style having opacity too.
the svg itself is generated through a program .
my question is this: is there another android library for svg parsing ? i searched and couldn't find .
does the google code site doens't have the latest code ?(google i heard stopped supporting it)
is there another way to give opacity to the stop element which doesn't include the style attribute ?
or most annoying option should I wait for whoever wrote it to fix it ?(commented on google code project site also but the last comment is from 2014 don't know if i get referrenced at all).
help would be appreciated thanks !
There is another to give opacity to the stop element which doesn't include the style attribute, mapped CSS attributes e.g.
<stop offset="0.1774" stop-color="#EDEDED" stop-opacity="0.2"/>

Resource not found exception at setDropDownBackgroundColor

I'm trying to set a DropDown Background Color for a autocompleteTextView, because the standart Values seem to be different during different Android Versions. For example, everything works fine starting with android 3.2, but previous Versions seem to not accept the android:textColor="#color/black" in the xml, cause it is not working for me. Android 2.3 for example just shows the items in the list and the ones I picked in white, which isn't working for me, cause the background is white too. So I decided to change the background Color determing on the android version using this:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB){
// Do something for Honeycomb and above versions
//everything is right
} else{
// do something for phones running an SDK before froyo
box_Kurs.setDropDownBackgroundResource(Color.BLUE);
box_Teacher.setDropDownBackgroundResource(Color.BLUE);
}
But when I start my app it crashes and shows resource not found exception:
11-19 15:40:17.225: E/AndroidRuntime(450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shr.khg/com.shr.khg.AddActivity}: android.content.res.Resources$NotFoundException: Resource ID #0xff0000ff
What am I doing wrong? I alread cleaned my project since that what other people suggested. Or is there any easier way to deal with my issue?
Thank you!
The problem is that the setDropDownBackgroundResource() is expecting the id of the Color resource Drawable, not an int that defines a Color. If you look at the Exception you can see that Android is trying to find a component with id #0xff0000ff, this is the hex code for a completely opaque blue which is the value of Color.BLUE
Replce these two lines:
box_Kurs.setDropDownBackgroundResource(Color.parseColor("#0000ff"));
box_Teacher.setDropDownBackgroundResource(Color.parseColor("#0000ff"));

Custom error popup window background

Is there any way to set a custom layout for an error popup window in TextView:
.
In textView.setError(String, Drawable) we can set an error icon only.
showError() method in TextView and ErrorPopup class are private, so I can't work with them.
Any ideas? Thanks in advance! Michael
UPD:
Thanks for comments, but as I understand it, the theme trick isn't applicable here:
(TextView 3384 line from android-10)
void fixDirection(boolean above) {
mAbove = above;
if (above) {
mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error_above);
} else {
mView.setBackgroundResource(com.android.internal.R.drawable.popup_inline_error);
}
}
In android-15 com.android.internal.R.styleable.Theme_errorMessageBackground theme parameter is used, but it is internal.
Therefore I don't see any way to solve this problem, except writing my own error notificator ):

Categories

Resources