Action Tab background during orientation change doesn't change properly - android

Action bar navigation tabs are merged in the action bar when going into landscape mode, so I defined a values-land folder with a colors.xml file where I set the appropriate background color and text color for the merged tabs. Long story short:
these are the correct colors for portrait mode
this is what happens when I rotate the screen to landscape mode
When i launch the app starting from landscape mode instead, and then changing to portrait, this is what I get:
the activity starts with the correct colors for landscape, as defined by me in values-land/colors.xml
these is what happens when rotating the screen to portrait mode
Only the tab's text color changes accordingly to my instructions.
The activity has launchMode="singleTask" (which is mandatory for my case), but even with launchMode="standard" the problem persists. I'm starting to think this is an API bug... Is there any workaround for this, like some way to force the redrawing of the action bar?
edit: my <activity> tag:
<activity
android:name="com.rocca.controlloSpese.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

It seems like you've set up the Android manifest such that the activity isn't destroyed during rotations. Unless you have a strong case to do that, you should let the activity be destroyed and recreated when rotating.

after deeper research and a few attempts, I found out what it was. When switching to landscape mode, the system looks for "-land" qualifiers and updates the views accordingly, like everybody knows. Therefore it updates my tab's text color because it finds a values-land/ directory in which there is a colors.xml file with the specific colors.
The tabs' background is defined by drawables and I put them in the drawable directory, because they are the same shape both for landscape and portrait, only colors change. So there is no drawable-land directory, but this means that the system will not redraw the backgrounds and will recycle them, missing the fact that inside those drawables there are references to values that must change. The solution was to add a drawable-land directory with a copy of the background drawables, so that the system will know that it must redraw the views. It will redraw the same views, but at least it will use the different colors.

Related

How can I recolor texts and icons that exist in androidx.preference, BottomNavigationView, and DrawerLayout automatically when the user changes theme

The user can change the appearance of the app from the SettingsFragment.
The SettingsFragment built using androidx.preference
When the user changes the appearance from the app settings, onConfigurationChanged will be called instead of recreating the activity.
That means I should set the colors to texts and icons that exist in androidx.preference, BottomNavigationView, and DrawerLayout by myself.
I want to ask if is there any way to recolor texts and icons that exists in androidx.preference, BottomNavigationView, and DrawerLayout automatically not manually.
Manifest
<activity
android:name=".activities.MainActivity"
android:configChanges="uiMode">
...
</activity>
I don't know if the question is clear or not. Ask me if anything is not clear. Thank you.

Android: view is displayed before calling setContentView R.layout

I'm studing an app and debugging it. I set breakpoint on first line of onCreate in MainActivity. However, app action bar is displayed before the next line "setContentView(R.layout." and before "super.onCreate" is stepped over. In other app action bar is for some reason not displayed even after I step over "setContentView(R.layout." (however screen becomes white with only status bar). Apps both have activity_main.xml, manifests describe both as
<activity
android:name=".MainActivity"
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
View that is displyed before setContentView is called differs that it includes custom View class, I set breakpoints in it's constructors, they are called during setContentView.
Why one app shows action bar before setContentView and in second case action bar is not shown even right after setContentView?
Thank you!
Maybe this is related to theme attribute which is set in AndroidManifest.xml for that activity ?
Activity with normal theme (with toolbar/actionbar enabled) is showing with this toolbar even before setting layout to give perception of fast loading app.
While Activity with disabled toolbar/actionbar via theme is not showing it at the beginning till layout is really inflated and added.

Android - How to avoid delay when calling setTitle() in activity's onCreate()

The title of my SplashActivity is quite long, so appears truncated beneath the launch icon on the device's home screen.
I want a shorter title shown beneath the launch icon, but a longer title shown in the Activity's action bar.
So, to try and achieve this I have specified a shorter title in the manifest...
<activity
android:name=".SplashActivity"
android:label="#string/app_name_short"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...and I'm using...
setTitle(getString(R.string.app_name));
...in the onCreate() method of SplashActivity so that the full title appears in the action bar.
It works, but only after about a 1 second delay. (So when SplashActivity is displayed, it shows the short title for 1 second before changing to the longer title.)
Is there any way I can fix this or any known workaround?
I've also tried creating a PreSplashActivity (with a short title) as the launch activity, including code to immediately launch SplashActivity (with a long title), but PreSplashActivity is still displayed for 1 second (even though it doesn't call setContentView(), so I'm a bit stumped.
Any ideas?
In this post answered by mark Renouf made it know that intent-filters can have a label attribute If it's absent the label is inherited from the parent component
Have you looked at the new docs for API21, specifically Toolbar? http://developer.android.com/reference/android/widget/Toolbar.html
With the new Toolbar you include it in your layout file like any other view. A nice side effect of this is that the initial screen is blank and the action bar appears in sync with the rest of your content. This gives you the option to set the title and make any customizations necessary before it becomes visible.
Here's details about using AppCompat to support older versions, it includes a section on using Toolbar in your layout and setting it as the action bar: http://android-developers.blogspot.ie/2014/10/appcompat-v21-material-design-for-pre.html

How place ActionBarSherlock at the bottom?

I'm using ActionBarSherlock and I need to place it at the bottom.
Is there any way to do this?
Can I just set android:gravity="bottom" in style.xml?
Firstly, you cannot change the position of the ActionBarSherlock. It will always be displayed on the top. However, you can easily put your tabs and other contents you add in the ActionBar to be displayed at the bottom.
I also had a similar problem. I solved it by putting android:uiOptions="splitActionBarWhenNarrow" within the <activity> tag.
For example, this worked:
<activity android:name=".my.Activity"
android:uiOptions="splitActionBarWhenNarrow"/>
However, only in portrait mode it will actually show at the bottom of the screen. So, you will have to define your application orientation in the manifest as portrait, otherwise it will again go to the top.

Android - How to improve ListView performance when setting Theme.Translucent.NoTitleBar in Activity?

I have an activity with Theme.Translucent.NoTitleBar set as the activity's style attribute in the manifest.xml.
<activity android:theme="#android:style/Theme.Translucent.NoTitleBar"/>
I need that, because when launching the activity, I animate the rootlayout of this activity from the bottom to the top (like the ModalPresentation on iPhone) and I don't want to have a black background during this animation.
Everythings works, but the performance of the ListView I put in this rootlayout is very slow after applying the translucent theme.
I already tried setting BackgroundColors of the ListView and the rootlayout, but it seems, that android still considers the transparency while drawing.
Have you tried: getWindow().setFormat(PixelFormat.RGBA_4444); in onCreate()?

Categories

Resources