问题
i just spent some hours on making the Actionbar visible without success:
With my RegisterActivity i collect some login data and then i start MainActivity. In RegisterActivity i have a Actionbar but not in MainActivity:
AndroidManifest:
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="17"/>
<application android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity android:name="RegisterActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:theme="@android:style/Theme.Holo" >
</activity>
</application>
RegisterActivity:
...
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("username", username);
i.putExtra("password", password);
startActivity(i);
...
MainActivity:
...
webview = new WebView(this);
setContentView(webview);
webview.loadUrl(address);
...
Normally there should be an Actionbar but there isn't!
just hope that someone has a solution for my problem?!
Thanks
回答1:
I solved my problem:
My RegisterActivity extends the Class Activity! My MainActivity extends the class DroidGap from Phonegap2.5.0 (aka Apache Cordova).
I changed MainActivity so that it extends Activity and the result is that the ActionBar is visible :D
When you need DroidGap you will have to insert
super.setBooleanProperty("showTitle", true);
before you call:
super.onCreate(savedInstanceState);
At the end it looks like this:
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.setBooleanProperty("showTitle", true);
super.onCreate(savedInstanceState);
//More Code ....
回答2:
The correct way of setting the boolean property ShowTitle is using the preferences in the config.xml.
add
<preference name="ShowTitle" value="true"/>
to config.xml to enable the ActionBar on Android.
回答3:
Are you sure that there is no line:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
in onCreate() method?
Try:
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
...
setContentView(...);
...
or
...
this.requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
...
来源:https://stackoverflow.com/questions/15789199/android-actionbar-is-hidden-with-droidgap-phonegap-cordova