4

アクションバーを実装しましたが、そのタイトルが表示されません。また、私のアプリには 2 つのフラグメントがあり、表示されるフラグメントに従ってタイトルが変更されるはずです。

public class MainActivity extends FragmentActivity  {
    /** Called when the activity is first created. */

     AppSectionsPagerAdapter mAppSectionsPagerAdapter;

     ViewPager mViewPager;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

       setupActionBar();

        mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());


        // user swipes between sections.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mAppSectionsPagerAdapter);
        mViewPager.setOnPageChangeListener(new OnPageChangeListener() 
        {
            public void onPageSelected(int position) 
            {
            }

            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) 
            {

            }

            public void onPageScrollStateChanged(int state) 
            {
                if (state == ViewPager.SCROLL_STATE_DRAGGING)
                {

                }
                if (state == ViewPager.SCROLL_STATE_IDLE)
                {

                }
            }
        });


    }


    public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {



        public AppSectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            switch (i) {
                case 0:


                    return new AllPatient();

               case 1:

                    //Intent intent = new Intent(MainActivity.this,abc.class);
                     return new LaunchpadSectionFragment();



            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;

        }



    }




    private void setupActionBar() {
        ActionBar actionBar = getActionBar();
        //actionBar.setDisplayShowHomeEnabled(false);


       actionBar.setBackgroundDrawable(new ColorDrawable(Color.WHITE));

       actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                ActionBar.DISPLAY_SHOW_CUSTOM);
       ViewGroup v = (ViewGroup)LayoutInflater.from(this)
               .inflate(R.layout.header, null);
        actionBar.setCustomView(v,
                new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
                        ActionBar.LayoutParams.WRAP_CONTENT,
                        Gravity.CENTER_VERTICAL | Gravity.RIGHT));
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(getTitle());

    } 


}

アクションバーのアイコン間に仕切りを追加する方法も教えてください。前もって感謝します。

4

4 に答える 4

3

この行を変更してみてください:

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);

これによって:

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME, ActionBar.DISPLAY_SHOW_CUSTOM);
于 2013-06-05T10:53:52.560 に答える