我正在尝试在蜂窝上使用AppCompat actionBar,但我无法做到。它适用于API> = 14。
这是我的AppTheme
:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/AppTheme.ActionBarStyle</item>
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:buttonStyle">@style/RobotoButtonStyle</item>
<item name="android:windowBackground">@color/background</item>
</style>
其他奇怪的事情是getActionBar()
总是返回null
。
我在Gingerbread上看到了同样的问题,但在Honeycomb上却没有。
这是我的目标API:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
整个清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.estudiotrilha.inevent"
android:versionCode="17"
android:versionName="2.0.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- <uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="com.estudiotrilha.inevent.permission.C2D_MESSAGE" />
<uses-permission android:name="com.estudiotrilha.inevent.permission.C2D_MESSAGE" /> -->
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name="InEvent" >
<meta-data android:name="DATABASE" android:value="in_event.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.estudiotrilha.inevent.content" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_id" />
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="SOME**KEY"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name="com.estudiotrilha.inevent.ProfileEventActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.estudiotrilha.inevent.DemoActivity"
android:label="@string/app_name"
android:theme="@style/Transparent"
android:parentActivityName="com.estudiotrilha.inevent.ProfileEventActivity">
</activity>
<activity
android:name="com.estudiotrilha.inevent.EventActivity"
android:label="@string/app_name">
</activity>
<activity
android:name="com.estudiotrilha.inevent.LectureNewActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.EventActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.LectureActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.EventActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.QuestionarieActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.LectureActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.MaterialsActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.LectureActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.PresenceActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.LectureActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.PersonActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.EventActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.ProfileActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.ProfileEventActivity" >
</activity>
<activity
android:name="com.estudiotrilha.inevent.SignInActivity"
android:label="@string/app_name">
</activity>
<activity
android:name="com.estudiotrilha.inevent.SignInWithLinkedInActivity"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:parentActivityName="com.estudiotrilha.inevent.SignInActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="x-oauthflow-linkedin" android:host="com.estudiotrilha.inevent" />
</intent-filter>
</activity>
<activity
android:name="com.estudiotrilha.inevent.SignInManuallyActivity"
android:label="@string/app_name"
android:parentActivityName="com.estudiotrilha.inevent.SignInActivity" >
</activity>
<!-- <service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.estudiotrilha.inevent" />
</intent-filter>
</receiver>
<receiver android:name="com.estudiotrilha.inevent.helper.Broadcast" android:exported="false">
<intent-filter>
<action android:name="com.estudiotrilha.inevent.PUSH_NOTIFICATION" />
</intent-filter>
</receiver>-->
</application>
</manifest>
主要活动:
package com.estudiotrilha.inevent;
import org.apache.http.HttpResponse;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import com.estudiotrilha.inevent.content.ContentHelper;
import com.estudiotrilha.inevent.content.GlobalContents;
import com.estudiotrilha.inevent.content.Person;
import com.estudiotrilha.inevent.fragment.SignInFragment;
import com.estudiotrilha.inevent.helper.ToastHelper;
import com.estudiotrilha.inevent.net.DefAPI;
import com.estudiotrilha.inevent.net.Delegate;
import com.google.code.linkedinapi.client.LinkedInApiClientFactory;
import com.google.code.linkedinapi.client.oauth.LinkedInAccessToken;
import com.google.code.linkedinapi.client.oauth.LinkedInOAuthService;
import com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceFactory;
import com.google.code.linkedinapi.client.oauth.LinkedInRequestToken;
import com.sromku.simple.fb.SimpleFacebook;
public class SignInActivity extends FragmentActivity
{
protected static final String TAG = "SignIn";
public static final String PREFS_NAME = "com.estudiotrilha.inevent";
public Fragment currentFragment = null;
public SimpleFacebook mSimpleFacebook = null;
public LinkedInOAuthService oAuthService;
public LinkedInApiClientFactory factory;
public LinkedInRequestToken liToken;
public ProgressDialog dialog = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_with_fragment);
GlobalContents.setNowActivity(this);
getActionBar().setTitle(R.string.SignIn);
if (savedInstanceState == null) {
currentFragment = new SignInFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.container, currentFragment).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mSimpleFacebook.onActivityResult(this, requestCode, resultCode, data);
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
dialog = ProgressDialog.show(this, "",
getString(R.string.signInProgress), true);
String verifier = intent.getData().getQueryParameter("oauth_verifier");
class LinkedInToken extends AsyncTask<String, String, String>
{
String verifier;
LinkedInAccessToken accessToken;
public LinkedInToken(String verifier) { this.verifier = verifier; }
@Override
protected String doInBackground(String... params)
{
accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.d("TOKEN", accessToken.getTokenSecret());
class SignInWithLinkedIn implements Delegate
{
private DefAPI api;
public SignInWithLinkedIn()
{
api = new DefAPI(this);
Person.signInWithLinkedIn(accessToken.getTokenSecret(), api);
}
@Override
public void requestResults(HttpResponse response, JSONObject result,
String value)
{
dialog.dismiss();
if(response != null)
{
switch(response.getStatusLine().getStatusCode())
{
case 200:
ContentHelper ch = ContentHelper.getContentHelper();
Person authenticatedPerson;
try
{
authenticatedPerson = new Person(result.getJSONArray("data").getJSONObject(0));
ch.insertAuthenticatedUser(authenticatedPerson);
Intent intent = new Intent(SignInActivity.this, ProfileEventActivity.class);
startActivity(intent);
SignInActivity.this.finish();
}
catch (JSONException e)
{
ToastHelper.make(R.string.toastNetworkError);
e.printStackTrace();
}
break;
default:
ToastHelper.make(R.string.toastNetworkError);
break;
}
}
else
{
ToastHelper.make(R.string.toastNetworkError);
}
}
@Override
public DefAPI getAPI() {
return api;
}
@Override
public Context getContext() {
return SignInActivity.this;
}
@Override
public void bitmapDelegate(Bitmap bm, int position, int id) {
// TODO Auto-generated method stub
}
}
new SignInWithLinkedIn();
}
}
new LinkedInToken(verifier).execute("");
}
class LinkedInLogin extends AsyncTask<String, String, String>
{
@Override
protected String doInBackground(String... params)
{
oAuthService = LinkedInOAuthServiceFactory
.getInstance()
.createLinkedInOAuthService(
"KEY","KEY2"
);
factory = LinkedInApiClientFactory
.newInstance("7obxzmefk9eu","rPsCyb8npka6jJHk");
liToken = oAuthService.getOAuthRequestToken("x-oauthflow-linkedin://com.estudiotrilha.inevent");
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
intentToLinkedIn();
}
}
public void startLinkedInLogin()
{
new LinkedInLogin().execute("");
}
public void intentToLinkedIn()
{
dialog.dismiss();
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse(liToken.getAuthorizationUrl()));
startActivity(i);
}
}
感谢。
答案 0 :(得分:0)
如果你的min SDK是7-9,你的活动应该延长ActionBarActivity并使用getSupportActionBar()。
如果你的min SDK是10或更高,那么扩展Activity并使用常规的HOLO主题。