2016-06-21 15 views
-1

ライブラリcom.roughike:bottom-bar:1.2.1を使用して、下部タブを使用してAndroidアプリを作成しています。問題は、彼のgithubには、タブがどのようにフラグメントで動作するかに関する実際の例はないということです。私はその周りを歩こうとしましたが、成功しませんでした。以下にコードを示します。タブとフラグメント

public class MainActivity extends AppCompatActivity { 
private CoordinatorLayout coordinatorLayout; 

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

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.three_buttons_activity); 

    BottomBar bottomBar = BottomBar.attach(this, savedInstanceState); 
    bottomBar.setItemsFromMenu(R.menu.three_buttons_menu, new OnMenuTabSelectedListener() { 
     @Override 
     public void onMenuItemSelected(int itemId) { 
      switch (itemId) { 
       case R.id.recent_item: 
        //Snackbar.make(coordinatorLayout, "Recent Item Selected", Snackbar.LENGTH_LONG).show(); 
        break; 
       case R.id.favorite_item: 
        //Snackbar.make(coordinatorLayout, "Favorite Item Selected", Snackbar.LENGTH_LONG).show(); 
        break; 
       case R.id.location_item: 
        //Snackbar.make(coordinatorLayout, "Location Item Selected", Snackbar.LENGTH_LONG).show(); 
        break; 
      } 
     } 
    }); 

    bottomBar.setActiveTabColor("#FFFFFF"); 
} 
} 

私は、「最近の項目を」選択した場合、それは最近のアイテムタブに移動し、そのタブに何でもやるが、それは私には起こらないだろう例えば持っていると思いました。

あなたがたのうち、右のそれを行う方法についての良い提案と例を持っている場合、私はそれを本当に感謝します。..

おかげ

答えて

1

私は一年以上前にこの下のバーを使用していました。これは私がどのようにフラグメントを追加したかです。

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_three_buttons); 


     // ************* Setting Up The Bottom Bar ************ // 

     BottomBar bottomBar = BottomBar.attach(this, savedInstanceState); 
     bottomBar.noTabletGoodness(); 

     // *********** Adding Item Fragments to the bottom Bar ************ // 

     bottomBar.setFragmentItems(getSupportFragmentManager(), R.id.fragmentContainer, 
       new BottomBarFragment(ProfileFragment.newInstance("Content For Profile"), R.drawable.ic_profile, "Profile"), 
     new BottomBarFragment(MessagesFragment.newInstance(), R.drawable.ic_chat, "Messages")); 
     // bottomBar.setActiveTabColor("#009688"); 
     bottomBar.setActiveTabColor(getResources().getColor(R.color.blue)); 
    } 

そして断片クラスの1:

public class ProfileFragment extends Fragment { 
    public static ProfileFragment newInstance(String text) { 
     Bundle args = new Bundle(); 
     args.putString(STARTING_TEXT, text); 
     ProfileFragment homeFragment = new ProfileFragment(); 
     homeFragment.setArguments(args); 
     return homeFragment; 
    } 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.layout_profile_fragment, container, false); 

       // do your stuff 

     return rootView; 
} 
+0

はどうもありがとうございます... – Raven

+0

M.Waqasパルヴェーズもう一つ。私は自分のfragment_layout.xmlにlistviewとtextviewを入れようとしましたが、実行しようとすると常に空白になります。私はこのコードをonCreateViewのフラグメントに入れました。TextView tvTest =(TextView)getView()。findViewById(R.id.tvTest); tvTest.setText(STARTING_TEXT);何も起こりません。 – Raven

+0

@Ravenはあなたのコードを更新します。私が見てみましょう –

関連する問題