yog*_*jhi 0 android android-fragments instagram android-recyclerview bottomnavigationview
我是一名 android 新手,试图为我的新 android 应用程序创建一个底部导航栏,类似于 Instagram 中的导航栏。像这样
单击搜索图标会在操作栏中添加一个搜索栏。我正在构建一个应用程序,用于提醒用户他的医疗预约,底部有三个导航选项卡。我已经创造了这个
在这之后我被卡住了。我是否应该使用三个活动来显示相应选项卡或片段的内容,以及如何实现。
我需要一个recyclerview来显示约会。如何仅在单击底部的搜索图标时显示搜索栏。已经搜索了很多实现这一点,但找不到任何有用的东西。
任何对实现相同的代码或库的建议都会有很大帮助,谢谢。
我应该使用三个
activities来显示相应的内容tabs还是fragments如何实现?
绝对你应该Fragment用于每个底部导航Item / Tab。像FragmentHome,FragmentSearch和FragmentSettings。
要更改Fragment,请添加NavigationItemSelectedListener到您的BottomNavigationView并Fragment根据MenuItem选择进行更改:
BottomNavigationView bottomNavigationView = (BottomNavigationView)
findViewById(R.id.bottom_navigation_view);
bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Fragment selectedFragment = null;
switch (item.getItemId()) {
case R.id.action_item1:
selectedFragment = FragmentHome.newInstance();
break;
case R.id.action_item2:
selectedFragment = FragmentSearch.newInstance();
break;
case R.id.action_item3:
selectedFragment = FragmentSettings.newInstance();
break;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个关于:BottomNavigationView with multiple Fragments的教程
我需要一个
recyclerview来显示约会
在您的Fragment's布局中XML,添加一个RecyclerView以显示约会列表。在您的Fragment课程中,初始化RecyclerView并创建一个ArrayList<Appointment>并将其传递list给您Adapter以RecyclerView在行项目上显示。
这是一个关于:如何在 Fragment 中使用 RecyclerView的教程
如何
search bar仅在search单击底部的图标时显示?
您可以ToolBar/ActionBar根据片段更改以编程方式显示/隐藏选项项目。
在您的 中FragmentSearch,执行以下更改以显示Searchbar:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.fragmet_search, parent, false);
return v;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.your_search_menu_xml, menu);
super.onCreateOptionsMenu(menu, inflater);
}
Run Code Online (Sandbox Code Playgroud)
以下是一些有用的链接:
希望这将有助于理解场景。
| 归档时间: |
|
| 查看次数: |
13816 次 |
| 最近记录: |