Ich habe vor kurzem festgestellt, dass wenn ein Link in einigen wenigen Android-Apps geöffnet ist, haben sie dieses ähnliche Look and Feel und die benutzerdefinierten Aktionsmenüs mit der "Powered by Chrome "unterhalb des benutzerdefinierten Menüs. Welche Komponente wird in diesem verwendet oder ist es immer noch das Chrom WebView
? Hoffentlich möchte ich sie zu meinen nächsten Projekten hinzufügen, die den Link in einer App öffnen.Öffnen von benutzerdefinierten WebView mit "Powered By Chrome" Mit Aktionsmenüs
6
A
Antwort
5
Es ist Chrome Custom Tabs. Sie können den Beispielcode von Google Chrome here sehen.
Versuchen Sie, die folgende util Klasse:
public class CustomTabs {
private static final int TOOLBAR_SHARE_ITEM_ID = 1;
public static void openTab(Context context, String url) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
enableUrlBarHiding(builder);
setToolbarColor(context, builder);
setSecondaryToolbarColor(context, builder);
setCloseButtonIcon(context, builder);
setShowTitle(builder);
setAnimations(context, builder);
setShareActionButton(context, builder, url);
addToolbarShareItem(context, builder, url);
addShareMenuItem(builder);
addCopyMenuItem(context, builder);
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(context, Uri.parse(url));
}
/* Enables the url bar to hide as the user scrolls down on the page */
private static void enableUrlBarHiding(CustomTabsIntent.Builder builder) {
builder.enableUrlBarHiding();
}
/* Sets the toolbar color */
private static void setToolbarColor(Context context, CustomTabsIntent.Builder builder) {
builder.setToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
}
/* Sets the secondary toolbar color */
private static void setSecondaryToolbarColor(Context context, CustomTabsIntent.Builder builder) {
builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.colorPrimary));
}
/* Sets the Close button icon for the custom tab */
private static void setCloseButtonIcon(Context context, CustomTabsIntent.Builder builder) {
builder.setCloseButtonIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_arrow_back));
}
/* Sets whether the title should be shown in the custom tab */
private static void setShowTitle(CustomTabsIntent.Builder builder) {
builder.setShowTitle(true);
}
/* Sets animations */
private static void setAnimations(Context context, CustomTabsIntent.Builder builder) {
builder.setStartAnimations(context, R.anim.slide_in_right, R.anim.slide_out_left);
builder.setExitAnimations(context, R.anim.slide_in_left, R.anim.slide_out_right);
}
/* Sets share action button that is displayed in the Toolbar */
private static void setShareActionButton(Context context, CustomTabsIntent.Builder builder, String url) {
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_menu_share);
String label = "Share via";
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
shareIntent.setType("text/plain");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setActionButton(icon, label, pendingIntent);
}
/* Adds share item that is displayed in the secondary Toolbar */
private static void addToolbarShareItem(Context context, CustomTabsIntent.Builder builder, String url) {
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_menu_share);
String label = "Share via";
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
shareIntent.setType("text/plain");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addToolbarItem(TOOLBAR_SHARE_ITEM_ID, icon, label, pendingIntent);
}
/* Adds a default share item to the menu */
private static void addShareMenuItem(CustomTabsIntent.Builder builder) {
builder.addDefaultShareMenuItem();
}
/* Adds a copy item to the menu */
private static void addCopyMenuItem(Context context, CustomTabsIntent.Builder builder) {
String label = "Copy";
Intent intent = new Intent(context, CopyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addMenuItem(label, pendingIntent);
}
public static class CopyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String url = intent.getDataString();
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData data = ClipData.newPlainText("Link", url);
clipboardManager.setPrimaryClip(data);
Toast.makeText(context, "Copied " + url, Toast.LENGTH_SHORT).show();
}
}
}
Vergessen Sie nicht, um die Abhängigkeiten zu Ihrem app/build.gradle
dependencies {
...
compile 'com.android.support:customtabs:25.2.0'
}
und registrieren Sie Ihre BroadcastReceiver
in Ihrem AndroidManifest.xml
<application>
...
<receiver android:name=".CustomTabs$CopyBroadcastReceiver" />
</application>
Verwandte Themen
- 1. Wie ändern Powered By Liferay
- 2. X-powered-By Entfernung
- 3. Was bedeutet "x-powered by"?
- 4. Ausblenden X-Powered-By (nginx)
- 5. X-Powered-By-Header von Azure Traffic Manager festgelegt
- 6. Entfernen powered by oneall in opencart
- 7. Versteckt PHPs X-Powered-By-Header
- 8. B4A - Webview mit Chrome-Browser
- 9. WebView mit benutzerdefinierten HTTP-Client
- 10. Python Webbrowser Öffnen von URLs mit Chrome
- 11. Wie wird "Powered by ..." in Pelican CMS automatisch entfernt?
- 12. Android Studio Webview mit benutzerdefinierten CSS (jsoup)
- 13. Wie man 'Quickfix' Titel umbenannt powered by setloclist Builtin-Funktion?
- 14. Android WebView Post Anfrage mit benutzerdefinierten Kopfzeilen
- 15. Erstellen von benutzerdefinierten WebView mit Cordova 5.0 in Android
- 16. Wie Chrome-Browser mit bestimmten Größen öffnen
- 17. Mit chrome öffnen anstatt es herunterzuladen
- 18. Wie aggregiert (mit "by") eine data.table mit benutzerdefinierten Spaltennamen ohne ": ="?
- 19. C# URL in Chrome mit Hash (#) öffnen
- 20. OAuth 2.0-Anmeldung mit benutzerdefinierten Chrome-Tabs (Fitbit-API)
- 21. App als Browser mit benutzerdefinierten Filter öffnen
- 22. Öffnen der Kamera von android webView
- 23. Django Powered Sites
- 24. So löschen Sie benutzerdefinierte IIS-Header wie X-Powered-By: ASP.NET aus Antwort?
- 25. Open Link von webview in Chrome für Android
- 26. Erkennen, ob Chrome Webview ist?
- 27. Android Webview mit WebGL
- 28. WebView Capture Navigation zu einem benutzerdefinierten Protokoll
- 29. Link zum Öffnen von iTunes von Chrome
- 30. Wie Google Chrome öffnen Selen in einem benutzerdefinierten Profil in Python mit [Betriebssystem: Ubuntu]
See hinzuzufügen: https://developer.chrome.com/multidevice/android/customtabs –