如何修改Google Picker中星标DocsView的默认标题?
I see the issue here — when you enable the setStarred(true) flag on a DocsView, the Google Picker API automatically falls back to using "Google Drive" as the default title, overriding any implicit or expected default labels. The fix is straightforward: you just need to explicitly call the setTitle() method on your starred DocsView to set your custom name.
Here's how to adjust your code:
this.picker = new google.picker.PickerBuilder() .addView(new google.picker.DocsView(google.picker.ViewId.DOCS) .setIncludeFolders(true) .setOwnedByMe(true)) .addView(new google.picker.DocsView(google.picker.ViewId.DOCS) .setIncludeFolders(true) .setOwnedByMe(false)) .addView(google.picker.ViewId.RECENTLY_PICKED) .addView(new google.picker.DocsView(google.picker.ViewId.DOCS) .setStarred(true) .setTitle('Starred')) // Add this line to set your custom title .setAppId(this.clientId) .enableFeature(google.picker.Feature.MULTISELECT_ENABLED) .disableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES) .setOAuthToken(accessToken) .setLocale('es') .setTitle('Selecciona uno o varios archivos') .setCallback(this._pickerCallback.bind(this)) .build() .setVisible(true);
Why this works:
When you configure a DocsView with special filters like setStarred(true), the Picker API prioritizes its own default localized labels unless you explicitly override them with setTitle(). This is different from regular DocsView instances (like your "owned by me" or "shared with me" views) which use default labels based on their configuration without needing explicit title overrides.
Adding the .setTitle('Starred') call directly to your starred view will replace the default "Google Drive" text with your custom title, matching the behavior of your other views.
内容的提问来源于stack exchange,提问作者Aldeguer

