我是android的新手,我想通过在android studio中制作一个简单的聊天应用程序来学习。
我首先创建了一个导航抽屉。现在我想的标签添加到我的应用程序像这样-下面抽屉式导航栏聊天/联系人/通话,但我无法找到这样一个简单的教程一步一步。
在启动此聊天应用程序之前,我使用了一个简单的应用程序,并向该旧应用程序添加了一些选项卡,如下所示:
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources resources = getResources();
TabHost tabHost = getTabHost();
// First tab
Intent intentTabOne = new Intent().setClass(this, TabOneActivity.class);
TabSpec tabSpecTabOne = tabHost
.newTabSpec("Tab One")
.setIndicator("", resources.getDrawable(R.drawable.icon_one_config))
.setContent(intentTabOne);
// Second tab
Intent intentTabTwo = new Intent().setClass(this, TabTwoActivity.class);
TabSpec tabSpecSecondTab = tabHost
.newTabSpec("Tab Two")
.setIndicator("", resources.getDrawable(R.drawable.icon_two_config))
.setContent(intentTabTwo);
// Third tab
Intent intentTabThree = new Intent().setClass(this, TabThree.class);
TabSpec tabSpecSent = tabHost
.newTabSpec("Tab Three")
.setIndicator("", resources.getDrawable(R.drawable.icon_three_invitations_config))
.setContent(intentTabThree);
// add all tabs
tabHost.addTab(tabSpecTabOne);
tabHost.addTab(tabSpecTabTwo);
tabHost.addTab(tabSpecTabThree);
//set Windows tab as default
tabHost.setCurrentTab(0);
}
但是现在我的主要活动是这样的:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed()...
另外,由于TabActivity现在已被弃用,我想应该使用片段,所以我有点迷路了。如果有人能指出我正确的方向,我将不胜感激。提前致谢。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句