2015-04-27 4 views
0

Я хочу использовать ActionBar без расширения ActionBarActivity, потому что я уже расширил TabActivity. Может ли кто-нибудь помочь?android ActionBar Без расширения ActionBarActivity?

Я сделал что-то вроде этого. в этом я хочу реализовать панель действий

+4

'TabActivity' устарел ** более четырех лет **. Пожалуйста, используйте современные методы для вкладок, таких как «ViewPager» с индикатором с вкладками. – CommonsWare

ответ

0

попробуйте мой код. Вы сможете иметь фрагменты с панелью действий и tabhost.

1) XML file for Activity: 

    <?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <HorizontalScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:scrollbars="none"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 
     </HorizontalScrollView> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 

    </LinearLayout> 
</android.support.v4.app.FragmentTabHost> 


2) Java code for Activity: 

    public class CarsActivity extends FragmentActivity implements YourFragment.OnFragmentInteractionListener 
    { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    _mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
    _mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 
    //add your fragments here: 
    _mTabHost.addTab(_mTabHost.newTabSpec("*UNIQE IDENTIFIER OF YOUR FRAGMENT").setIndicator("*DISPLAY NAME ON TAB*"), 
       YourFragment.class, null); 
    } 
    }); 
    @Override 
    public void onFragmentInteraction(Uri uri) 
     {} 

    } 
0

Вы можете использовать getActionBar() в oncreate() или если вы хотите создать пользовательские панели действий используйте код ниже.

// Action Bar Customization 
    ActionBar ab =act.getActionBar(); 

    ColorDrawable colorDrawable = new ColorDrawable(act.getResources().getColor(color.ActionBar_bg)); 
    ab.setBackgroundDrawable(colorDrawable); 

    //ab.setBackgroundDrawable(act.getResources().getDrawable(R.drawable.header)); 
    ab.setDisplayShowTitleEnabled(false); // disables default title on 
              // actionbar. 
    ab.setDisplayShowCustomEnabled(true); // enables custom view. 
    ab.setDisplayShowHomeEnabled(false); // hides app icon. 
    ab.setTitle(""); 
    // Inflating Layout 
    LayoutInflater inflater = (LayoutInflater) act.getActionBar() 
      .getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE); 

    View customActionBar = inflater.inflate(R.layout.actionbar_layout, null); 

    imgapplogo = (ImageView) customActionBar.findViewById(R.id.app_logo); 
    img_back=(ImageView)customActionBar.findViewById(R.id.imgBack); 
Смежные вопросы