2012-02-06 25 views
19

Tôi đang sử dụng một ShareActionProvider và muốn tận dụng lợi thế của ActionBar được tách khi không có đủ chỗ cho nó ở trên cùng - android:uiOptions="splitActionBarWhenNarrow".ShareActionProvider với một ActionBar chia

Hành động hoạt động tốt khi ActionBar không cần phải chia:

landscape

Tuy nhiên khi ActionBar không cần phải chia, các cấp tác dường như phá vỡ bố cục ActionBar thấp hơn hoàn toàn. Nó lấp đầy toàn bộ khung nhìn dưới ActionBar đầu và hành động tự nó không xuất hiện:

portrait

Có ai đã có thể sử dụng hai tính năng này lại với nhau thành công?

+2

vBulletin báo cáo lỗi đệ: http://code.google.com/p/androi d/issues/detail? id = 26027 –

+0

Tôi đã xem xét sự cố cho bạn. Cùng một vấn đề ở đây. Tôi gặp lỗi tương tự khi sử dụng tính năng mới nhất có sẵn theo nhận xét này. Thanh tác vụ Appcompat. – danny117

Trả lời

0

Nếu không quan trọng, bạn có thể sử dụng ActionBarSherlock, ví dụ này từ bản demo: Portrait Landscape Landscape expand

/* 
* Copyright (C) 2011 The Android Open Source Project 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License. 
* You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package com.actionbarsherlock.sample.demos; 

import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 

import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.widget.TextView; 

import com.actionbarsherlock.app.SherlockActivity; 
import com.actionbarsherlock.view.Menu; 
import com.actionbarsherlock.view.MenuItem; 
import com.actionbarsherlock.widget.ShareActionProvider; 

/** 
* This activity demonstrates how to use an {@link android.view.ActionProvider} 
* for adding functionality to the Action Bar. In particular this demo is adding 
* a menu item with ShareActionProvider as its action provider. The 
* ShareActionProvider is responsible for managing the UI for sharing actions. 
*/ 
public class ShareActionProviders extends SherlockActivity { 

    private static final String SHARED_FILE_NAME = "shared.png"; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     setTheme(SampleList.THEME); //Used for theme switching in samples 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.text); 
     ((TextView)findViewById(R.id.text)).setText(R.string.share_action_providers_content); 
     copyPrivateRawResuorceToPubliclyAccessibleFile(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate your menu. 
     getSupportMenuInflater().inflate(R.menu.share_action_provider, menu); 

     // Set file with share history to the provider and set the share intent. 
     MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar); 
     ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider(); 
     actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); 
     // Note that you can set/change the intent any time, 
     // say when the user has selected an image. 
     actionProvider.setShareIntent(createShareIntent()); 

     //XXX: For now, ShareActionProviders must be displayed on the action bar 
     // Set file with share history to the provider and set the share intent. 
     //MenuItem overflowItem = menu.findItem(R.id.menu_item_share_action_provider_overflow); 
     //ShareActionProvider overflowProvider = 
     // (ShareActionProvider) overflowItem.getActionProvider(); 
     //overflowProvider.setShareHistoryFileName(
     // ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); 
     // Note that you can set/change the intent any time, 
     // say when the user has selected an image. 
     //overflowProvider.setShareIntent(createShareIntent()); 

     return true; 
    } 

    /** 
    * Creates a sharing {@link Intent}. 
    * 
    * @return The sharing intent. 
    */ 
    private Intent createShareIntent() { 
     Intent shareIntent = new Intent(Intent.ACTION_SEND); 
     shareIntent.setType("image/*"); 
     Uri uri = Uri.fromFile(getFileStreamPath("shared.png")); 
     shareIntent.putExtra(Intent.EXTRA_STREAM, uri); 
     return shareIntent; 
    } 

    /** 
    * Copies a private raw resource content to a publicly readable 
    * file such that the latter can be shared with other applications. 
    */ 
    private void copyPrivateRawResuorceToPubliclyAccessibleFile() { 
     InputStream inputStream = null; 
     FileOutputStream outputStream = null; 
     try { 
      inputStream = getResources().openRawResource(R.raw.robot); 
      outputStream = openFileOutput(SHARED_FILE_NAME, 
        Context.MODE_WORLD_READABLE | Context.MODE_APPEND); 
      byte[] buffer = new byte[1024]; 
      int length = 0; 
      try { 
       while ((length = inputStream.read(buffer)) > 0){ 
        outputStream.write(buffer, 0, length); 
       } 
      } catch (IOException ioe) { 
       /* ignore */ 
      } 
     } catch (FileNotFoundException fnfe) { 
      /* ignore */ 
     } finally { 
      try { 
       inputStream.close(); 
      } catch (IOException ioe) { 
       /* ignore */ 
      } 
      try { 
       outputStream.close(); 
      } catch (IOException ioe) { 
       /* ignore */ 
      } 
     } 
    } 
} 

https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ShareActionProviders.java

+1

Sai. Nếu bạn sử dụng thanh tác vụ chia tách với bản trình diễn đó ('android: uiOptions =" ​​splitActionBarWhenNarrow "'), nó sẽ hiển thị chính xác cùng một vấn đề trên pre-ICS với ActionBarSherlock giống như với bản thực thi gốc. –

1

Một số cách tạo ra một lịch sử chia sẻ các bản sửa lỗi tập tin vấn đề này

này có thể được cố định bằng cách sử dụng một tập tin lịch sử chia sẻ tùy chỉnh trên ứng dụng cài đặt.

ví dụ: gọi CreateShareHisotryFile() trên App Tạo()

public class YourBrokenAPP extends Application { 

    public static SHARE_HISTORY_FILE_NAME = "c_share_hist.xml"; 

@Override 
public void onCreate() { 
    super.onCreate(); 
    CreateShareHisotryFile(); 
} 

private void CreateShareHisotryFile() { 

    String data = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?> "+ 
       "<historical-records>" + 
        "<historical-record activity=\"com.google.android.apps.plus/com.google.android.libraries.social.gateway.GatewayActivity\" time=\"1426500217970\" weight=\"1.0\" />"+ 
      "</historical-records>"; 
    try { 
     OutputStreamWriter outputStreamWriter = new  OutputStreamWriter(openFileOutput(SHARE_HISTORY_FILE_NAME, Context.MODE_PRIVATE)); 
     outputStreamWriter.write(data); 
     outputStreamWriter.close(); 
    } 
    catch (IOException e) { 
     Log.e("Exception", "File write failed: " + e.toString()); 
    } 
} 

sau đó trong onCreateOptionsMenu sử dụng file chia sẻ lịch sử của mảnh chúng ta vừa tạo ....

@Override 
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
    inflater.inflate(R.menu.main, menu); 

    // Set up ShareActionProvider's default share intent 
    MenuItem shareItem = menu.findItem(R.id.action_share); 
    mShareActionProvider = (ShareActionProvider) 
      MenuItemCompat.getActionProvider(shareItem); 
    mShareActionProvider.setShareHistoryFileName(c_share_hist.xml); 
} 

Lưu ý rằng lịch sử hồ sơ cần @ ít nhất một historical- phần tử con kỷ lục trong file xml

sau đó nó là tất cả tốt ENJOY .......

Các vấn đề liên quan