Actionbar on top of PhoneGap webview - android

I'm trying to add the actionbar of Android(4.0) to the webview activity of PhoneGap (2.0.0). I'm using the same actionbar in another activity in my application. It's in the menu.xml file and in the other activity everything is working without any problem.
When I load the webview, the actionbar is not shown.
I get a nullPointerExeption on the actionbar. I already have the #targetApi(14). And the resource is working for the homeactivity but not for the webviewactivity.
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar));
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setIcon(R.drawable.logo);
I found getActionBar is a function from the Activity class and this is returning null. Probably phonegap is giving a twist to the activty and therefore it is not possible to load the actionbar.
Anybody experience with this? Thanks

#Override
public void onCreate(Bundle savedInstanceState) {
super.setBooleanProperty("showTitle", true);
super.onCreate(savedInstanceState);
The setBooleanProperty before super.onCreate was the answer for the problem

Related

Can't set Logo in ActionBar

I've seriously tried everything.
I've tried both setLogo() and setIcon().
I've tried adding android:logo="" in manifest.
I've made sure to try both supportActionBar and regular ActionBar. (I'm running sdk 21 with a min sdk of 15.)
The funny thing is if I try to use the regular ActionBar I get null pointers but when I use the support ActionBar it at least works.
Is there anything else I can try...? Here's where I try and change it.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar ab = getSupportActionBar();
ab.setLogo(R.drawable.logo);
If your min sdk is 15, i'm not sure why you're using the support package at all.
You class should instead extend Activity, and use getActionBar().

Error while using setDisplayHomeAsUpEnabled in FadingActionBarHelper

I want to implement FadingActionBar in my application to get the effects like latest Google play Music app.
Below is how i am using the FadingActionBar
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FadingActionBarHelper helper = new FadingActionBarHelper()
.actionBarBackground(R.drawable.ab_background)
.headerLayout(R.layout.header)
.contentLayout(R.layout.activity_listview);
setContentView(helper.createView(this));
helper.initActionBar(this);
Here i wanted to add back button in actionBar using setDisplayHomeAsUpEnabled(true);
I am getting error while adding the above code saying no such method found.
My question is there any way to add setDisplayHomeAsUpEnabled(true);
if not, how we can add back button for FadingActionBar
i had the same problem but it was because i was using appcompat v7 so you just have to add this.
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Or
getActionBar().setDisplayHomeAsUpEnabled(true);
Hope it helps

How to hide the actionbar in some activities

I have an application, when I test it in 2.3.3 the activities I want don't have an actionbar, but when I test it in emulator using 4.2, those activities have an action bar.
How can I remove the actionbar completely from those activities.
I tried this from here:
android:theme="#android:style/Theme.NoTitleBar"
Doesn't work.
If I use getActionBar().hide(), and test it on my 2.3.3 it crashes. And if I try getSupportActionBar().hide() i get error: The method getSupportActionBar() is undefined. Note: I am not extending actionbar activity. I am extending Activity.
(From the comments I wrote)
First, make your classes extends ActionBarActivity. Then call this method in the onCreate() callback of the activies in which you want to hide the action bar:
private void hideActionBar() {
//Hide the action bar only if it exists
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
}
You can hide the action bar with the getActionBar().hide() method (Or getSupportActionBar().hide is you are using support library.
or
You can call requestWindowFeature(Window.FEATURE_NO_TITLE); in onCreate method before calling setContentView.

Android How to change the title for each activity using actionbarsherlock [duplicate]

This question already has answers here:
How to change the text on the action bar
(19 answers)
Closed 8 years ago.
I want to know that how can i use the different title for each activity using ActionBarSherlock. Like Setting's Activity should label Settings on the title bar etc
public class Main extends SherlockActivity implements OnClickListener, OnItemClickListener, OnItemLongClickListener
in each activity you can call programmatically
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(title);
it takes as parameter both an int or a charsequence. Lile setText of a TextView
You mean how to set the title in the Actionbar? In that case it is:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setTitle(R.string.yourString);
....
If I understood the question correctly, you can do this by:
<activity android:name=".ActivityName"
android:label="#string/settings">
</activity>
And to do this for each of your activities, which are defined in the AndroidManifest.
This is the way to set tile..
ActionBar ab = getActionBar();
ab.setTitle("My Title");
u can use it in your manifest where you declare
<activity android name ".pckgname"
android : label = "activity name"
>
</actrivity>
and remove this method from your activity
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Android loading icon in title bar across multiple activities

I am using the code from this post to put a loading icon in the title bar of my Android App:
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.your_layout);
}
The code:
activity.setProgressBarIndeterminateVisibility(true);
is called in an AsyncTask. If the user navigates to a new activity, the icon is not longer present in the title bar since the icon was set for the first activity only.
Is there a way to have the icon show on all activities? Thanks in advance.
You can create super activity (i.e. Base Activity), include the below line in this super activity:
activity.setProgressBarIndeterminateVisibility(true);
And extends this activity to all the child activities.

Categories

Resources