I am really new to android so pardon me. Why is there a strike-through
for example (fill_parent)
in some android variables and not others
The strikeout shows deprecated methods or attributes (assuming you are using Android Studio / IntelliJ). In your case FILL_PARENT (LayoutParams?) is deprecated for a really long time (API Level 8). It is now called MATCH_PARENT (see https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html). Hovering the variable should show you a tooltip with more information on the deprecation and when it was deprecated. Just make sure you don't use those deprecated elements.
Related
I have a fragment where on onCreateView() I set its root view's paddingTop programmatically to show it below an overlay actionbar. I simply call:
root.setPadding(0,
Math.round(getResources().getDimension(R.dimen.abc_action_bar_default_height_material)),
0, 0);
This works great on all devices I test until I build the apk with proguard. Then only on devices running API 16 (so far that I tested), the padding doesn't get updated and the root view goes under the actionbar.
I tried many changes to my proguard configuration to no avail. The latest try follows this configuration adding exceptions to all views and support libraries.
I also changed the code to add a log on my onCreateView() and I can see it on my console with the right padding value to be updated. It just doesn't show on the UI only for these devices on API 16.
And the fact that it works when debugging, makes finding a solution for this that much harder. Any ideas?
Use getDimensionPixelOffset instead of getDimension
I just updated the support library - and the new SwipeRefreshLayout is not my taste. Is there a way to get the old style back? There are still the setColor methods - which is kind of strange - they seem to have no use anmore. I really hope to have the old style I do not have to stick to the old library.
I actually had to do this as well - I needed the "Holo" SwipeRefreshLayout with the top horizontal line indicator as opposed to the pull-down-rotating-arrow indicator.
You can actually just reference an older version of the android support library in your project if you want the old SwipeRefreshLayout; e.g.
compile 'com.android.support:support-v4:21.0.+'
I'm not sure if version 21 is old enough; you might have to go back to 20. The caveat here is of course if you need functionality from one of the newer support library versions you won't have access to that functionality.
I want to know if someone knows a library that contains a back ported implementation for ListPopupMenu that works on pre android 11
I don't but you could use PopupWindow whcich is available since API 1. You can create a list as your contentView. You can use showAsDropDown which could give you the same type of effect
This might be worth checking out. I like to use it for backwards compatibility sometimes for the effect it gives
PopupWindow
showAsDropDown
I have noticed that the setBackground method for the RelativeLayout object is targeted for API 16 (Android 4.1) and higher, but my application has the target API 8 and I cannot use it.
Is there any alternative solution for this problem (besides marking the class/method with TargetApi(16) or changing the target API in the manifest)?
Thank you!
Edit: Eclipse was buggy and it showed me the same error for setBackgroundDrawable but now it seems to work. Thank you for your help.
Use one of:
.setBackgroundColor(int) (if you're setting it to a color)
.setBackgroundDrawable(Drawable) (if you're setting it to a Drawable type; this is deprecated, and was replaced by .setBackground(Drawable))
.setBackgroundResource(int) (for setting a resource from R.java)
If you use the second one, make sure to do a conditional check on your API version:
if (Build.VERSION.SDK_INT >= 16)
view.setBackground(...);
else
view.setBackgroundDrawable(...);
... and mark it with #TargetApi(16) and #SuppressWarnings("deprecation").
It depends. If you want to set a color as the background, use setBackgroundColor(). For a Drawable, you can use the now deprecated method setBackgroundDrawable() for APIs below 16, and setBackground() for API 16 devices. You can also use setBackgroundResource() for setting a resource as the background.
Note that while a lot of methods are marked as deprecated, I'm yet to come across one that has actually been removed. So while you could use the deprecated method even in API 16, I'd recommend setting your target API to 16 and using an if else to switch between the methods, depending on the API version the device is running.
Use setBackgroundDrawable() instead. It does the same thing, but it's been deprecated since the new setBackground() method.
I have an edittext in my application that will show the cursor correctly in Froyo or Gingerbread, however in later sdks the cursor is invisible. I have found online the solution is to set the android:textCursorDrawable="#null" so that the edittext will use the font color for the cursor. However, since my minsdkversion is 8, I do not have access to that property.
Is their either a way to selectively add a property based on the sdk you are on? Or possibly a way to work around this so that I can have visible cursors on both older and newer sdk versions?
I don't know your current setup, but one way to use that property is to use different layouts folders based on various android versions. android:textCursorDrawable is a property introduced in API 12 so you could have a layout folder like layout-v12 which will be used where the API is 12 or greater. In the layouts from this folder the use of the property is valid.
For lower versions, Froyo and Gingerbread, you don't have any problems so you would use a default folder, layout. In the end you'll have two layouts folder(containing the same layout files):
layout // don't need the property
layout-v12 // use the property
That leaves out API 11, I don't know if this is a deal breaker for you.
Try setting your targetSdkVersion to API level 13 or higher to gain access to the android:textCursorDrawable property
If you not has a cursor I guess the input is simple and say you only can enter new chars at end of the text?
I think you can use a TextView and to this add you own KeyListener?
But in this case you will has problem with the virtual keyboard not is show, see some of this links:
Forcing the Soft Keyboard open
android force keyboard visible
or create you own keyboard if the rang of valid keys is very limit as only digits.