Adding View in xml layout android 2.2+ - android

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.

Related

Views and atributtes from android layout

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.

Show error for unsupported custom attribute

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

Objects visibility

I've done a lot of search but can't find the difference between tools:visibility = "visible" and android:visibility = "visible" ? Which situation I must use tools or android?
Here is the Simple Explanantion:
tools:visibility = "visible" is used to manipulate view visibility on the IDE.It wont affect the view in the real time.It just used for Designing purpose in Android Studio
while
android:visibility = "visible" is the actual code which will be executed in run-time and will make changes to your views
Ref: http://tools.android.com/tips/layout-designtime-attributes
tools: attributes only contribute to design time preview while editing layouts while
android: actually affects how it will be displayed on actual device.
You can find further information here and here.
The exactly question should be
"What the difference between android:... and tools:... on Layout
XML files"
tools is one of the Design Attributes that can facilitate layout creation in XML in the development framework.This attribute is used to show the development framework what activity class is picked for implementing the layout. Using “tools:context”, Android Studio chooses the necessary theme for the preview automatically
Android is used in run-time app, when you launch your apk in a device
according to here
If you see the Design Time Layout Attributes
The tools namespace is a specially recognized namespace by the Android tools, so all the attributes you define on view elements in the tools-namespace will be automatically stripped when the application is packaged and there is no runtime overhead.
So if we need to test something in layout editor only during development time which doesn't affect at runtime, we can use the tools namespace.
Example:
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
tools:visibility="invisible" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second"
tools:visibility="visible" />
If the above layout is rendered in Android Studio designer view, first Button will be invisible. But at run time, it will be visible.
TOOLS values will be used only in layout preview in Android Studio.t
ANDROID values will be used in app as normal.
So if you set values for main container:
tools:visibility:"gone"
android:visibility:"visible"
The main container in layout preview in AS will be gone, but if you launch app on emulator / device it will be visible.

Android API 21 ignores layout_marginEnd and uses layout_marginRight instead in EditText

Here is my EditText.
My issue is that Android ignores the layout_marginEnd in Lollipop and above
and uses layout_marginRight instead.
See two screenshots below:
<EditText
android:id="#+id/foo_count_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/foo_container"
android:layout_marginEnd="20dp"
android:layout_marginRight="100dp"
android:layout_marginTop="-6dp"
android:hint="#string/foo_default_value"
android:imeOptions="actionDone"
android:inputType="number"/>
As can be seen, in API 21 (left) the margin is 100dp, taken from layout_marginRight and not layout_marginEnd.
Edit:
#ErnirErlingsson Nailed it: Need to enable android:supportsRtl in the manifest in order to use layout_marginEnd instead of layout_marginRight.
Thanks.
Edit 2:
Note however that in API 17 (right screenshot) the right margin is taken from layout_marginEnd while the android:supportsRtl is false.
One replaces the other, if you decide to support RTL now or in the future you should always use marginStart and marginEnd instead of using marginRight and marginLeft, otherwise you are fine with the latter.
http://developer.android.com/about/versions/android-4.2.html#RTL
According to the corresponding docs RTL support should be disabled per default and therefore the left/right margins should be used. To my knowledge this does not differ between the OS's versions that are visible on the screenshots that you posted with your question, so as to exactly why this is happening is a bit of a mystery. My first guess is that this has something to do with the emulator and I would confirm this on actual devices with the respective OS versions.
EDIT
When supporting older OS versions you do indeed need to add both to your layout but to make sure that marginStart and marginEnd are used you need to set the android:supportsRtl attribute to true. Check out the first link I posted above for more information.

Can't set alpha of ImageView in XML

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)

Categories

Resources