Hy,
When using views and atributtes like the next ones configuring an android layout:
<ImageView
android:src="#android:drawable/ic_partial_secure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/imageView" />
The number of views and values of these atributtes depend on the api level you are working on?
If it does, how can I know I am not using an atributte or a view that will not be present on an Android device with an api which not contains this atributte?
Thanks
Yes, there are some attributes that require a min API, take a look at this:
android:actionBarStyle requires API level 11
if it does and your min API level (in your build.gradle) is too low then android will tell you.
Related
I make a layout for API 17 and API 21. I add here a TextView. and assign id in API 17, in API 21 I use TextView and add some more attributes that not supported in API 17.
../layout-v17/activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/padding"
android:id="#+id/user_name"
android:text="#string/user_name"/>
../layout-v21/activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/padding"
android:id="#+id/user_name"
android:text="#string/user_name"
android:elevation="#dimen/elevation"/>
Is it necessary to use ID in both versions? and Why?
If you are referencing those IDs in your code then they are needed.
They can be removed if you are not using them .
IDs are not needed if you don't need to access those elements programatically. But if you do, you can use the same ID, but make sure if you are programmatically manipulating the element and using any methods that are not available across all APIs that you check the version you are running on before calling those methods.
I am working on an Android Library, which makes buttons of different shapes. The Button's XML looks like this:
<com.singh.daman.mybutton.ShapedButton
android:id="#+id/round"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:fill_color="#color/colorPrimaryDark"
app:button_type="round_rectangle"
app:stroke_color="#color/colorAccent"
app:stroke_width="12sp"
app:text="Round Rectangle"
app:text_size="16sp"
app:text_color="#ffff"
android:layout_gravity="center"
android:background="#null" />
In which attribute app:button_type="round_rectangle" have different values like rectangle, star, circle and round rectangle.
The type round_rectangle is supported by only Lollipop and Above android versions.
So, When the library user sets button_type to round_rectangle and the app minimum android version is less than Lollipop, I want to show an error that it is only supported by api 21 and above, How can I do that?
You need a custom lint rule. I've never done this, but there are writeups from Google on the topic.
http://tools.android.com/tips/lint-custom-rules
My layout code below, using android:layout_alignStart, was working flawlessly in Eclipse. However, recently I switched to the official Android Studio. When I use the alignStart property there, Android Studio underlines it with a wavy red line and says "To support older versions than API 17(project specifies 9) you should also add android:layout_alignLeft="#+id/textview1".
However, I tried replacing it as recommended by Android Studio, and I do not get the output alignStart was supposed to give! I am trying to place dataView2 to the right of textView2, but it currently lies on top of textView2...
<TextView
android:id="#+id/dataView2"
android:layout_toRightOf="#+id/textView2"
android:layout_alignStart="#+id/dataView1"
android:layout_alignBelow="#+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/planet_mass_label" />
Currently your minSdk is 9, so you're getting that red line which says "To support older versions than API 17(project specifies 9) you should also add android:layout_alignLeft="#+id/textview1".
Refer this link: http://android-developers.blogspot.in/2013/03/native-rtl-support-in-android-42.html
If you want your minSdk to be 9 or less than 17, than you should use both, android:layout_alignLeft="#+id/dataView1"
android:layout_alignStart="#+id/dataView1"
accordingly.
Since your original code uses layout_alignStart="#+id/dataView1", the line you should add for pre-API 17 compatibility is
android:layout_alignLeft="#+id/dataView1"
not
android:layout_alignLeft="#+id/textView1"
The final code should be
<TextView
android:id="#+id/dataView2"
android:layout_toRightOf="#+id/textView2"
android:layout_alignStart="#+id/dataView1"
android:layout_alignLeft="#+id/dataView1"
android:layout_alignBelow="#+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/planet_mass_label" />
I use this code in order to adding a line between my GUI componenets
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#3f9fe0"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/titleOfSection"
android:id="#+id/sectionLine"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
but it seemst that View is supporting from android api level 14+. I am using support library so it is possible to change this code in a way that android 2.2+ support the View too?
You are wrong, Views was created since api 1 as stated in the documentation.
I just tried your code with a minimum of 1 and maximum of 8 and it still works maybe you are referring to a different View, because if View does not exist since api 1 then buttons, TextView, etc wont exist as well because they inherits from View.
I'm compiling using API 16, but with the minimum supported API set to 8. I'm trying to set the alpha of an ImageView in XML, but every time I use
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0"
.
.
. />
AAPT complains that alpha isn't a valid attribute, even if the documentation in the android site states that ImageView's supposed to inherit it from View.
Is this a bug, or is this really how it's supposed to work. I'd set the Visibility, but that won't work well with my animations to show and hide the image.
Yes. You said that your min is 8. However, the View's alpha xml attribute doesn't appear until API Level 11.
http://developer.android.com/reference/android/view/View.html#setAlpha(float)