Force RTL layout direction not working - android

I am trying to add RTL support in my app where layout direction should also change to RTL on force setting to RTL.
I have followed:
Set minSdkVersion to 19 ,
Added android:supportsRtl="true" to application tag in AndroidManifest.xml,
Switched left/right attributes to start/end
Followed this link.
However, even when I use the "Force RTL Layout Direction", my app doesn't display the RTL layout. The system UI is flipped to RTL, and other apps also support RTL.
Is there anything else that need to be done?

in manifest.xml
add android:supportsRtl="true" in tag
and in every activity add this line in onCreate method
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

There is a much easier way to do the above changes without going through all the files and then doing it manually. Android Studio can do this for you.
Just go to Android Studio > Refactor > Add RTL support where
possible…
or
try to use this link :
link

Found the reason:
was using older version of mixpanel library
compile "com.mixpanel.android:mixpanel-android:4.6.0"
updated to latest version
compile "com.mixpanel.android:mixpanel-android:5.4.0"
hence ,check the libarary version,n update to latest.

Related

Failed to load AppCompat ActionBar with unknown error.Android Studio 3.1.3

This was my first time using Android studio and I dont know what are those errors mean or what they implyenter image description here
[Render Problem
Failed to load AppCompat ActionBar with unknown error.
Missing Constraints in ConstraintLayout
This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX). These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.]
Open, res --> values --> styles.xml, here you will find a line like this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Change DarkActionBar to NoActionBar
Please change com.android.support:appcompat-v7:28.0.0-alpha3 to com.android.support:appcompat-v7:28.0.0-alpha1 in build.gradle(Module: App).
And click File -> Invalidate Caches / Restart
Of course you need internet access.
It seems there is a bug in com.android.support:appcompat-v7:28.0.0-alpha3
Missing Constraints in Constraint Layout :-
It means some constraints values are not given like distance from the top ,bottom left and right .Here's a link to solve this problem.
And another link if you want to know more about constraint layout
If you are first time using Android studio then you should start with some simple layouts like linear or relative layout.
Hardcoded text :-
Ths is not an error but a warning. As a general rule, you should never use hardcoded strings in your layout but always use string resources (which means the all strings are stored in one separate file where they are easily changeable for different languages and so on).
To convert a hard coded String to a string ressource:
1:put the curser on the hard coded string
2:press ALT + Enter
3:enter a name for your resource
4:click OK
Use stable version always
Always use stable version of libraries. If you are developing an app, you don't want to face these type of errors.
At the time of answering the current most stable version is 27.1.1 and second 28.0.0-rc02.
I suggest use 27.1.1 until 28 stable version release.
implementation 'com.android.support:appcompat-v7:27.1.1'
Sync again
No need of Invalidate/ Restart, Just restart would be okay. Or closing project and reopening from recent would be faster then restart.
Track the support library release.

Android Studio: Add an activity to mobile (Material design)

I have a question about theme for Android app in Android Studio. When I'm creating a new project I would like to have an material design theme, but I don't get this activity theme to choose.
On first picture you can see my view for adding an activity and on second picture what I would like to have.
My current view
Material design view
Does anyone have a solution how to set up Android Studio so I can have a view which is showed on second picture?
I found the answer to this question.
To have this Project Template (Material design) available in Project Wizard, you need to have Android Studio version 1.4 or above.
For details see this link: Android Studio 1.4 Release
I don' t know if my as show that in the wizard. Bit materiale is a style. And this style is a guide line recommend by google. So you can make your app with material design also writing the code. For example you can use a floating action button, or a combo of beautiful color or pit simple animations inside yours views or using cards in listview.
If you have latest updated Android API, SDK, then you will get the material design by default; even if you would not use wizard for adding an activity.
Not sure if I'm barking up the wrong tree here, but just for reference, here are the Android SDK components I've got installed:
Here is the buildscript, android and dependency sections of my build.gradle:
And last but not least, Android Studio version:
If you couldn't find the tool fix, you can anyway inherit your activity from appcompactactivity.
And change your androidmanifest as follows to get material design feel
<application
//your stuff
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
Don't forget to add the following depenency in build.gradle and sync
compile 'com.android.support:appcompat-v7:22.0.0'

Android Studio enum left right bug? How to disable RTL warnings for whole project?

Android Studio should be known for those in most cases just aggravating Lint "Using left/right instead of start/end attributes" warnings. I'm using Android Studio 0.8.9, but the following problem was also present in earlier versions: If you add this ultra-minimal snippet anywhere in your code
public enum BiteMeLint {
LEFT
}
Android Studio shows the warning
Use "Gravity.START" instead of "Gravity.LEFT" to ensure correct behavior in right-to-left locales.
This also happens for the constant RIGHT, though it suggests to use Gravity.END in that case. Now I'm a developer who likes to keep his code completely clean of any warnings, either by complying or, if that's not possible, by suppressing and putting a "todo" or "fixme" where necessary. Here, since I'm using "LEFT" and "RIGHT" as constants for actual directions, the warning is obviously a bug. Sadly, adding
#SuppressLint("RtlHardcoded")
doesn't remove the warning. So how do I remove this joke of a warning? And now that I'm asking, can I somehow completely disable RTL warnings for a project I'm sure will never launch in a right-to-left locale?
According to this issue tracker, it is a bug which was fixed in Android Studio 0.8.10 recently.
The option to disable this inspection can be found under Project Settings | Inspections | Android Lint | Unsing left/right instead of start/end attributes. So you can simply disable it for the whole project by unchecking the box.
Android Studio 3
Go to File > Settings > Editor > Inspections > Android > Lint > Internationalization > Bidirectional Text.
Then uncheck Using left/right instead of start/end attributes.
But...
You may not want to actually disable the warning. It is there for a reason. Read what the Android Studio description says about it:
Using Gravity#LEFT
and Gravity#RIGHT can lead to problems when a layout is rendered in
locales where text flows from right to left. Use Gravity#START and
Gravity#END instead. Similarly, in XML gravity and layout_gravity
attributes, use start rather than left.
For XML attributes such as
paddingLeft and layout_marginLeft, use paddingStart and
layout_marginStart. NOTE: If your minSdkVersion is less than 17, you
should add both the older left/right attributes as well as the new
start/right attributes. On older platforms, where RTL is not supported
and the start/right attributes are unknown and therefore ignored, you
need the older left/right attributes. There is a separate lint check
which catches that type of error.
(Note: For Gravity#LEFT and
Gravity#START, you can use these constants even when targeting older
platforms, because the start bitmask is a superset of the left
bitmask. Therefore, you can use gravity="start" rather than
gravity="left|start".)
In the manifest, disabling the android:supportsRtl attribute will disable the Rtl lint warnings for the whole module
android:supportsRtl="false"

change action bar direction to right-to-left

I'm creating an android app for a right-to-left specific language. And I'm using ActionBarSherlock (a compatible android action bar library).
The thing I exactly want is how to change the direction of action bar to RTL even the user not sets the default Locale an RTL language.
If anyone has an idea even for standard android Action Bar it's valuable and may help please share it.
Thanks
From Android API Level 17+ it supports RTL natively. To force your entire layout to be RTL including the ActionBar do the following.
Edit your AndroidManifest.xml and add android:supportsRtl="true" to your <application> tag and then add the following line to the top of your Activities' onCreate() method forceRTLIfSupported(); and then insert the follow function into your Activity.
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
Of course that's only helpful for debugging. Use View.LAYOUT_DIRECTION_LOCALE for production builds so your layout is only changed when the user chosen system location/language aka locale supports RTL.
use this, It will be make layout from rtl but this in parent root of your xml
android:layoutDirection="rtl"
android:textDirection="rtl"
We must believe a powerful rule in programming:
Everything will be possible when you know your tools.
So, from now you can use this library to truly RTLize your actionbars:
https://github.com/semsamot/ActionBarRTLizer
And of course it is compatible with API Level 7+ .
Booger is right. The "Nabz Bazar" app that you mentioned does not align to the right on every version of android. As you can see here ABS doesn't really do anything on Android 4.0 or newer and the screenshots of that app are on a 4.2 android.
I am pretty sure you will not be able to do what you are asking. The ActionBar pattern is very specific, and the libraries supporting it would support the defined pattern only (which is having the icon on the top-left, then laying out title, and action buttons to the right).
Changing the test is as simple as changing the locale and text within your app (as you already alluded to).
Changing the position of the elements within the ActionBar itself will not be supported by the libraries that support the standard ActionBar pattern - as what you describe is not a supported UI pattern.
I think you should leave the AB as-is. It is not necessary to switch the order, as there is no right-left orientation anyway -and changing this will be extremely jarring to your users.
Bottom line, you won't be able to to this with the existing libraries - and you probably shouldn't anyway.
You can use one or all of them if your project is completely RTL language.
set on AndroidManifest.xml
<application
android:supportsRtl="true"
>
set in Xml.file
android:layoutDirection="rtl"
android:textDirection="rtl"
set in java.class
#TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void forceRTLIfSupported()
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
Kotlin:
Add forceRTLIfSupported() to the top of the onCreate() method of your Activity and then insert the following function into your Activity:
fun forceRTLIfSupported(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
window.decorView.layoutDirection = View.LAYOUT_DIRECTION_RTL
}
}

onConfigurationchanged is not called over jellybean(4.2.1)

I really suffer from this issue.
I already set the flag android:configChanges="keyboardHidden|orientation|locale"
But when I changed configuration of language, onconfigurationchanged function isn't called.
The strange thing is that my codes work fine over other android platform.
I searched this issue here.
Someone said that I need to set sdk version lower. But it didn't work.
Please give me some tips.
Add the layoutDirection attribute, such as android:configChanges="keyboardHidden|orientation|locale|layoutDirection" if you're working with API 17.
layoutDirection that is also connected with interface language changes was introduced in API 17. Piece of android docs about android:configChanges is not explicit enough about that fact, but at least we have:
layoutDirection: The layout direction has changed. For example, changing from
left-to-right (LTR) to right-to-left (RTL). Added in API level 17.
From Android 4.2, layout direction will be updated when we change language.
Then we have to add both "locale" and "layoutDirection" as below
android:configChanges="locale|layoutDirection",
that time onConfigurationChanged() will be called.
This is similar with "orientation" and "screenSize" in API 13.
do u config AndroidManifest.xml like this?
android:minSdkVersion="4" android:targetSdkVersion="17"
you need to remove android:targetSdkVersion attribute

Categories

Resources