Android: Remove all layout animations - java

So I've noticed Android generates a slight fade between activities which really bugs me and I was wondering if there was any way to get rid of it and just have it "snap" to the next screen with no animation at all?
I've looked around but I can't find anything that answers my question really. I was under the assumption that it would be XML based but I saw this guy trying to do it programmatically here:
How do I eliminate the delay before an LayoutTransition animation but doing what he did (applying a "blank" animation) didn't seem to change anything.
Could something point me in the right direction? Ta!

The most elegant control is achieved using styles and themes. This way, you can control this on a per-Application as well as per-Activity basis.
styles.xml (WhateverTheme being the Android theme you implicitly or explicitly chose for your app):
<resources
xmlns:android="http://schemas.android.com/apk/res/android" >
<style
name="MyWhateverTheme"
parent="#android:style/WhateverTheme">
<item name="android:windowAnimationStyle">#style/MyActivityAnim</item>
</style>
<style
name="MyActivityAnim">
<item name="android:windowEnterAnimation">#null</item>
<item name="android:windowExitAnimation">#null</item>
</style>
</resources>
Of course, you can also specify custom #animations this way.
In your Manifest.xml:
<application
android:theme="#style/MyWhateverTheme" >
and to change it for a particular Activity:
<activity
android:theme="#style/SomeOtherTheme" >

Use the FLAG_ACTIVITY_NO_ANIMATION
Intent i = new Intent(this, nextActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);

Related

Android Preset Login Activity - Title/Status bar will not go away. Have tried everything

Before someone marks this as a duplicate, I've spent hours looking through google and StackOverflow for answers to my problem and have not found any.
I've used the Android Studio Login Activity but I can't get the title bar to go away in that one activity (not the whole app). I've read over at least 10 different articles on how to do this, most of them say the same thing and none of it works. In fact, editing my .java class crashes my app. Is there a relation to this and the pre-built code involved in the Login Activity?
I've tried the following blocks of code in different orders in one of my java files:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
I've tried setting the NoActionBar theme in my XML file, as well as adding to the Manifest (which I don't want to do because that blankets the app... I just want the one page (login)'s title bar to go away.
I've tried everything that I could find on here and on google's search. Has anyone else ran into this problem while using the Login Activity in Studio?
Also, I found this answer -
"You should use 'NoActionBar' Style in 'styles.xml'. Than create
toolbar in your layout and add child view to your toolbar, set title
and modify as you like. "
This also does not work. I found that answer here: StackOverflow
Still no luck. I'd appreciate any advice. Thanks for your time!
EDIT: Someone told me to delete the ActionBar Class:
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
setupActionBar();
} }
Also deleted the call to actionBar. -- This also did not work.
I found this topic on Stack: Android Theme.TitleBar does not work
This was not helpful at all.
I tried this topic too which was also useless: How to hide the title bar for an Activity in XML with existing custom theme
When we create an Activity using Login Template, we see something like this -
public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> {....
Now, we can see that our Activity extends AppCompatActivity.
Thus, we need to create a custom style that extends AppCompat Theme, and override it to hide status bar.
First, in styles.xml, create a custom style as follows -
<style name="MyNoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Now, in AndroidManifest.xml, declare the "theme" attribute for the LoginActivity as follows -
<activity
android:name=".LoginActivity"
android:theme="#style/MyNoActionBarTheme"
android:label="#string/title_activity_login">
</activity>
As you can see from the image, the status bar is gone and the activity is now full-screen.
Do tell if this does not work for you. I too created a Login Template in Android Studio as the very first step.
If your LoginActivity is derived from AppCompatActivity then use below code to hide action bar.
getSupportActionBar().hide();
And if you are using toolbar as action bar then use this
((AppCompatActivity)getActivity()).getSupportActionBar().hide();
For AppCompat, following solution worked for me:
Add new theme style with no action bar in your styles.xml and set parent="Theme.AppCompat.NoActionBar".
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#color/colorPrimary</item>
</style>
Now implement the same theme style to your splash screen activity in androidManifest.xml
<activity
android:name=".ActivityName"
android:theme="#style/SplashTheme"> // apply splash them here
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Here is result:

How to change Android status bar color in all activities together

I learned how to color an Android activity status bar thanks to this solution: How to change status bar color to match app in Lollipop? [Android]
However it doesn't say how to make this for the entire app (all activities).
i don't want to duplicate those 4 lines of code into each Activity, and if I make a Java class for Utils, I can't reach my colors by using R.color.blue or getResources(....).
Is there a way to do this through the Manifest, perhaps? Or any other way?
Thank you!
You should create your own style in values/styles.xml. Then make your own theme with such parameters. Loock code below
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_secondary</item>
<item name="colorAccent">#color/color_accent</item>
<item name="android:statusBarColor">#color/color_primary</item><!--this is what you need-->
</style>
Or just use method (for Lolipop):
public abstract void setStatusBarColor (int color)

I want to hide my title bar in my android application [duplicate]

I am trying to use a custom title to include an image button to the title bar.
I got a lot of help form this post: android: adding button to the title of the app?, but could not get it work for my ListActivity.
In a nutshell, following is what I have:
I hide the titlebar in the AndroidManifest.xml
The specify a relative layout for the custom title (workorder_list_titlebar.xml)
My Activity Class looks like the following:
public class WorkOrderListActivity extends ListActivity {
String[] orders={"WO-12022009", "WO-12302009","WO-02122010", "02152010"};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.workorder_list_titlebar);
setContentView(R.layout.workorder_list);
setListAdapter(new ArrayAdapter(this,R.layout.workorder_list, R.id.label,orders));
}
}
When I ran the app, I got AndroidRuntimeException: You cannot combine custom titles with other title features.
Base on the stack trace, the exception was thrown by com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:183), that was triggered by setlistAdapter call.
Does anyone have the same problem with ListActivity?
Also once I manage to get this work, how do I attach listeners to the image button for it to do something?
Thanks in advance.
I had the same issue and I fix it deleting
<item name="android:windowNoTitle">true</item>
from my theme.xml
Make you create custom style in “values” folder. Make sure you code as below.
<style name="CustomTheme" parent="android:Theme">
Don't modify parent parameter.
This did work for me.
Instead of modifying your theme.xml you may also:
create a new XML style file my_theme.xml in values folder like this:
<style name="MyWindowTitleBackground">
<item name="android:background">#444444</item>
</style>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/MyWindowTitleBackground</item>
</style>
You may define other settings as you like in this theme.
Then just use this theme in your manifest within the activity's attributes
android:theme="#style/MyTheme"
Finally set your custom title as always in your activity.java:
final Window window = getWindow();
boolean useTitleFeature = false;
// If the window has a container, then we are not free
// to request window features.
if (window.getContainer() == null) {
useTitleFeature = window
.requestFeature(Window.FEATURE_CUSTOM_TITLE);
}
setContentView(R.layout.screen_main);
if (useTitleFeature) {
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
// Set up the custom title
main_title = (TextView) findViewById(R.id.title_left_text);
main_title.setText(R.string.app_name);
main_title = (TextView) findViewById(R.id.title_right_text);
main_title.setText(R.string.Main_titleInfo);
}
Don't forget to define the custom_title.xml file in your layout folder. For example...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TextView
android:id="#+id/title_left_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:ellipsize="end"
android:singleLine="true" />
<TextView
android:id="#+id/title_right_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#fff" />
</RelativeLayout>
I think notenking is right, that this is a problem in activities within tabs. Since some of my activities can either be stand-alone or within a tab, I've found the following helps:
final Window window = getWindow();
boolean useTitleFeature = false;
// If the window has a container, then we are not free
// to request window features.
if(window.getContainer() == null) {
useTitleFeature = window.requestFeature(Window.FEATURE_CUSTOM_TITLE);
}
setContentView(layoutId);
if (useTitleFeature) {
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}
May be you find this problem when use it in tab,for there already have a title and you can not add a custom title again.
you should add this custom title in the activity which you get the Tab
I did exactly as Sunny Dasari did but with one small change I put the # before and android in the parent attribute.
So my code looked like this.
<style name="CustomTheme" parent="#android:Theme">
To avoid crashing, you can simply add
android:theme="#style/android:Theme"
to the <Activity> tag in your AndroidManifest.xml:
<activity
android:name="test.TestActivity"
android:label="#string/app_name"
android:theme="#style/android:Theme">
This is because the styles defined in your default theme conflict with FEATURE_CUSTOM_TITLE (such as the attribute android:windowNoTitle). By using another theme, you can avoid such problems.
However, you might further need to define your own theme to change other attributes, such as android:windowTitleSize, background color, text color and font, etc. In this case, you can derive your theme from an existing theme (e.g., Theme.Light) and modify its attributes:
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="#style/android:Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleSize">60dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
Try swapping following lines:
setContentView(R.layout.workorder_list);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.workorder_list_titlebar);
I have run into this issue as well and it looks like it is an issue with what theme is applied to an activity in the AndroidManifest.xml file. If I use a theme like:
android:theme="#android:style/Theme.Holo
Then it will throw the error
android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
However if I use a different theme like:
android:theme="#android:style/Theme.Black"
then it will not throw the error and subsequently will not crash. However I am trying to use a theme like Theme.Holo. I'm not sure if there is a way around this.
Since, I was trying to compile my program in android 4.0, I was facing the same problem. None of these solutions helped.So, I copied my style contents from values > styles.xml and pasted it in values-v11 styles.xml file and values-v14 styles.xml file. Bingo, the trick worked.
As a beginner most of the answers didn't help me for my case. So here is my answer.
Go to res/values folder in your android project and check for strings.xml (this file may vary in your case, something like themes.xml)
Inside the file under resource tag check whether you have style tags. If you don't find it, add the code below as mentioned below as a child to resources tag
something like below
<resources>
<style name="SomeNameHere">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
if you already have style tag, just add the code below to your style tag
<item name="android:windowNoTitle">true</item>

Removing the Android Title Bar

I'm developing an android application and I cannot remove the title bar permanently. A solution posted here: How to hide the title bar for an Activity in XML with existing custom theme
(the 600 upvoted one, the others didn't work as described below) worked in general, but it maintained the title bar for a brief millisecond when initially launching the app.
I've tried various solutions throughout stackoverflow and other sites modifying the android theme in the manifest xml and style file(s). However, all of these solutions have all crashed the application before it began. The message in LogCat being that I must use an AppCompact theme. My main activity extends the ActionBarActivity class, and I have tried switching it to just Activity while also removing the :
if (savedInstanceState == null) {getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
that is generated. However, when I do so, all of the views on the main activity disappear and it becomes completely white with nothing else. Is there a way to completely remove the actionbar while extending ActionBarActivity? If not, how can I switch to extending Activity or some other class while maintaining no other errors?
on styles.xml you should make that
parent="Theme.AppCompat.NoActionBar"
Do you use custom view for the ActionBar? if yes, then maybe you'll find the approach I use acceptable. I just set text color for Title and Subtitle the same as background color in my app's theme.
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.ActionBar">
<item name="android:titleTextStyle">#style/ActionBar.Title</item>
<item name="android:subtitleTextStyle">#style/ActionBar.Subtitle</item>
<item name="android:background">#color/my_color</item>
<item name="android:backgroundStacked">#color/my_color</item>
<item name="android:backgroundSplit">#color/my_color</item>
</style>
<style name="ActionBar.Title">
<item name="android:textColor">#color/my_color</item>
</style>
<style name="ActionBar.Subtitle">
<item name="android:textColor">#color/my_color</item>
</style>
Then I inflate and apply custom ActionBar view in onCreate and set custom title

Android Styles For API 10 and API 11

I am trying to do something that I feel to be very simple in concept. I would like my app to be supported all the way back to API 10 (Gingerbread). To make this look good, I need to make a slight change to the color of the text on my buttons when the device is running API 10. Thus, I want to create two styles: one of which will be used when the device is using API 10 (I want the text color of the buttons to be black in this case), and another when the device is using API 11 or above (the text color will be the default ICS grayish in this case). To do this, I am using a values and a values-v11 folder. Inside the values folder is a themes.xml file with the following code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="buttonColorStyle">
<item name="android:textAppearanceButton">#style/buttonTextColor</item>
</style>
<style name="buttonTextColor">
<item name="android:textColor">#FFFFFF</item>
</style>
</resources>
However, when I load up my app with target SDK set to 10, the text color of the buttons is unchanged from the default grayish. Also, here is the code for one of my buttons which should use this style:
<Button
style="#style/buttonColorStyle"
android:id="#+id/thirdSectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="sectionButtonClicked"
android:text="Section 3"
android:textSize="11.5sp" />
Anyone have any ideas?
You have to do something like this:
<style name="MyStlye">
<item name="android:textAppearanceButton">#style/BtnText</item>
</style>
<style name="BtnText" parent="android:TextAppearance.Small.Inverse">
<item name="android:textColor">#android:color/black</item> // or whatever color
</style>
why not setting the same nice style for all versions?
you can use this library (also suggested at the android developers blog here) for making all of the devices use the holo theme.
alternatively , just leave the current style , so that the user will feel more "at home" with his current style of the OS (since it can change between companies) .

Categories

Resources