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.
Related
I'm writing my first app. I've done some practicals with Google Codelabs and learned to add an up navigation arrow to the app bar. When I try it with my app the navigation arrow is not anywhere.
The only difference between the practical and my code is the theme, which I've tried to change but the app stops when I do because I am not using an AppCompat theme which I have not learned yet. But I do not know if the theme is the problem.
<activity
android:name=".Lists"
android:label="#string/title_activity_lists"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.fourwomendev.simplyneatlist.MainActivity" />
</activity>
I expect a left pointing arrow to the left of the title of the activity Lists on the app bar, but there is not one.
I'm writing my first app. I've done some practicals with Google
Codelabs and learned to add an up navigation arrow to the app bar.
When I try it with my app the navigation arrow is not anywhere.
Because you are not using any Actionbar in your activity.
<activity
android:name=".Lists"
android:label="#string/title_activity_lists"
android:parentActivityName=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" //<-----no actionbar is
specified
>
.......
</activity>
Use one actionbar to get the left arrow.
In trying to work with errors from changing the theme I realized that the basic activity I chose when creating this activity is created with a toolbar in Java. So I took out the code that created the toolbar and the reference to the theme in XML and my up navigation arrow appeared.
In my app I've got an activity that's defined like this:
<activity android:name=".DocViewActivity"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen">
</activity>
What I see when starting this activity is, first the UI appears (quick, but animated), then the hiding of the title bar happens, (also quick, but animated).
What I want to do is wait for all of this to finish before proceeding. I've tried using an OnGlobalLayoutListener, but I think (though it's hard to confirm) that it's getting called before the title bar disappears.
So my question is, how can I know when the layout has finished and the title bar has disappeared?
You can try OnLayoutChangeListener on the title bar however I think all hiding animations will be done once you set it in onCreate what is the real purpose of this task?
Hey all I'd like help in creating my app in android studio I am new to this so I'll do my best to try and help you all understand best into what I am trying to do.
I am going to post two pics of how my design should look and I can't seem to get the start of the title bar done. In android studio it always on all of the project start-ups puts a black title bar with a picture of an android and its all black id like it to be cleared of the photo and re colour'd into red and the title text center'd as in my design image.
any help would be much appreciated
this should show the two pictures of my design
While you can edit the xml to change the ActionBar, your best bet is going to be using the new Toolbar. A toolbar is a fully customizable ActionBar without a lot of the traditional constraints of it. You can treat the toolbar just like any other layout container and include layout elements inside like TextViews, etc.
After you have designed your toolbar in xml, you can simply set the toolbar to be your action bar by calling activity.setSupportActionBar(yourToolbar);
This is much more flexible and allows much more control over the look and feel than using the traditional action bar.
Action bar custom label
AndroidManifest.xml:
<activity
android:name="com.package.app.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can change the android:label from your app name to your desired title for each activity you have.
Action bar background color
To change the action bar background, create a custom theme for your activity that overrides the actionBarStyle property. This property points to another style in which you can override the background property to specify a drawable resource for the action bar background.
Styling the Action Bar
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
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.