自定義選項卡是一作爲@pRaNaY的方式提及。這裏是一個快速的實現:
private static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR";
private static final String PACKAGE_NAME = "com.android.chrome";
private CustomTabsClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
warmUpChrome();
launchUrl();
}
private void warmUpChrome() {
CustomTabsServiceConnection service = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
}
};
CustomTabsClient.bindCustomTabsService(getApplicationContext(),PACKAGE_NAME, service);
}
private void launchUrl() {
Uri uri = getIntent().getData();
if (uri == null) {
return;
}
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
customTabsIntent.intent.setData(uri);
customTabsIntent.intent.putExtra(EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, getResources().getColor(R.color.red));
PackageManager packageManager = getPackageManager();
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(customTabsIntent.intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resolveInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
if (TextUtils.equals(packageName, PACKAGE_NAME))
customTabsIntent.intent.setPackage(PACKAGE_NAME);
}
customTabsIntent.launchUrl(this, uri);
}
搖籃:
compile "com.android.support:customtabs:23.0.0"
其他注意事項:
調用warmUpChrome儘早將切換到瀏覽器速度更快。該示例中的實現適用於深層鏈接,但如果要手動啓動它,請重寫launchUrl並提供URI或String作爲參數。這些代碼大部分是從其他的stackoverflow答案縫合在一起的,但我已經改變了它的一些部分以適合我的情況。
WebView對於我認爲的應用程序來說是足夠的。你面臨哪些問題?您的網站是否兼容? –
你會同意,在目前的形式下,這個問題是脫離主題(要求非現場資源)。如果你能解釋你的問題的確切性質...... – e4c5
看看新的[Chrome自定義標籤](http://android-developers.blogspot.in/2015/09/chrome-custom-tabs-smooth-transition.html )&[source](https://github.com/GoogleChrome/custom-tabs-client) – pRaNaY