android - how can i use the “android:layoutDirection”? - again - android

can someone help me how can i use this attribute android:layoutDirection ,
and please don't refer me to this question What is the status of Right To Left languages on Android? because it doesn't answer my question!

layoutDirection is not be published in 4.0,so you cannot use the attr,but if you not be using sdk,but build with all code of android.
first get the Linearlayout in your code when it created,normally after setContent,and using #hide api setLayoutDiredtion(View.LAYOUT_DIRECTION_LOCALE),which define in View.java
,of course,after 4.2 you can use layoutDirection in xml directly

Related

error with fab button design with vector assets

I have used the dependencies to be used as suggested. below is the pic.
build_gradle(module)
now I have selected a black plus icon from vector assets and named it as fab_plus, now I have this file in my drawable folder.
fab_plus_XML
now I tried to used that fab_plus_XML like this. Pic below.
activity_main
Now my question is why is the fab_plus is showing in red.
thanks in advance. pls, help me, someone.
There are two things wrong with the way you are specifying the drawable. To refer to a drawable within your project, you simply use #drawable/your_drawable and to allow backward compatibility of VectorDrawables you should use app:srcCompat as per the guidance.
So in your ImageView, instead of
android:src="#android:drawable/fab_plus"
you should have
app:srcCompat="#drawable/fab_plus"
You will also need to make sure the app namespace is included at the top of your layout xmlns:app="http://schemas.android.com/apk/res-auto" along with the current android and tools namespaces.
you need to use:
app:srcCompat
instead of
android:src
but the tooltip there should exactly tell you this and AFAIR even offer a quick-fix

Change Android CheckBox box's color programmatically (support library)?

I'm trying to change the checkbox box's color programmatically to a different color than the theme's default. The problem is I was doing something like this:
checkbox.setSupportButtonTintList(ColorStateList);
It works but it seems, according its class documentation, this method has been restricted to be used only by classes from the same package (com.android.support). This is the warning I got from Android Studio:
AppCompatCheckBox.setSupportButtonTintList can only be called from within the same library group (groupId=com.android.support)
Is there a standard/correct way of doing this for all API levels?
Finally, found the answer here from one of the Google guys: https://code.google.com/p/android/issues/detail?id=202235. I was right about not using:
checkbox.setSupportButtonTintList(ColorStateList);
It seems is a private API. Instead, you have to use:
CompoundButtonCompat.setButtonTintList(checkbox, colorStateList);
Based on rylexr answer, you can specify the color in the following way:
CompoundButtonCompat.setButtonTintList(checkboxView, ColorStateList
.valueOf(getResources().getColor(R.color.red)));
chxAll.setButtonTintList(ColorStateList.valueOf(Color.parseColor("#CC0000")));
chxAll is a object of android.widget.CheckBox
replace the hexacolor code for desigred color

Using android default buttons

I found these website http://androiddrawables.com/Buttons.html where you can check the differences between Android buttons .
How can I use them? If I type R.drawables.btn_star_big_on_pressed the editor says it couldn't find the resource.
How can I use those default Android images ?
I am using 4.0.
The only way I know how to use them is:
<ImageView
android:id="#+id/imageView"
android:layout_width="48px"
android:layout_height="48px"
android:src="#android:drawable/btn_radio" />
to check available buttons type first letter after drawable/.
Then navigate to the button and you will see the selectors.
You can do something like this,
android.R.drawable.btn_star
Default resources for UI components depend on the device and platform version that your app is running on. For your button's to use them you would want to simply not declare a background resource.
My advice is that you will go to the Android SDK folder/platforms/android-##/data/res/drawable-dpi and copy the icons from there into your own res folder.

Android Layout - when to use app: vs android:?

I've been writing some Android apps but I don't really understand when to use app: and when to use android:. When styles are not being applied the way they're supposed to, I use trial and error and sometimes find that using app: instead of android: solves the issue but I don't understand why. It'd be great if someone could point me in the right direction. Thanks!
You can use the app namespace to have app compatibility with older API versions.
For example
app:srcCompat="#drawable/customborder" has the same effects with
android:background="#drawable/customborder"
The difference is that the first will work correctly with older API's and the second will not display what you would like.
You are talking about custom namespace.In android we can create custom views in additional to already available views.
As per in Google developer docs..
To add a built-in View to your user interface, you specify it in an XML element and control its appearance and behavior with element attributes. Well-written custom views can also be added and styled via XML. To enable this behavior in your custom view, you must:
Define custom attributes for your view in a resource element
Specify values for the attributes in your XML layout
Retrieve attribute values at runtime
Apply the retrieved attribute values to your view
Once you define the custom attributes, you can use them in layout XML files just like built-in attributes. The only difference is that your custom attributes belong to a different namespace. Instead of belonging to the http://schemas.android.com/apk/res/android namespace, they belong to http://schemas.android.com/apk/res/[your package name]
So for if you use default views you can use android namespace and if you want to set and use attributes for custom view you can define your own name.
Refer this
If you take a look at the beginning of the your layout xml files (in which you used app:) you will (probably) find lines like this:
<?xml version="1.0" encoding="utf-8"?>
<SOME_LAYOUT xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
in this case app: namespace will be used for custom attributes, specified by you inside attrs.xml file or by someone else in one of used libraries.
Sometime the property with android only available in new Android version like
In this case, you should use app:... to make it work with older version.
moreover you will find two variants
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/[packagename]"
the difference between xmlns lines is res-auto take care of resolving our package as sometime we will add .debug or .test in our package and we already provided the packageid of the app Ex:
xmlns:app="http://schemas.android.com/apk/com.test.io.debug"
xmlns:app="http://schemas.android.com/apk/com.test.io.test"

Dynamic equivalent of these XML properties for a StackView

I am dynamically creating a StackView object in my Android project. How can I accomplish the following equivalent properties dynamically through code?
android:animateLayoutChanges="true"
android:loopViews="true"
Here's the first:
http://developer.android.com/reference/android/view/ViewGroup.html#setLayoutTransition
The second apparently has no related methods:
http://developer.android.com/reference/android/widget/AdapterViewAnimator.html#attr_android:loopViews
For animateLayoutChanges you can refer this.
And for the loopViews i am not getting any method but you can refer this.
Hope you got the Point. You can easilt search on developer site of Android for any other methods/function and its properties.
There is no way to change loopViews, but you can try to pass it through constructor using styles.

Categories

Resources