ActionBar diferente para cada fragment
24/10/2013
0
Cada fragment ter uma actionbar diferente
Alguém pode me dar uma luz, ajuda, o que vier agradeço.
Frederico Brigatte***
Posts
10/11/2015
Karla Nikiteko
11/11/2015
Karla Nikiteko
** * Created by karla on 27/10/15. */ import android.app.ActionBar; import android.content.Intent; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.TextDirectionHeuristic; import android.view.Gravity; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import org.w3c.dom.Text; import brliberty.com.tecner.www.liberty.view.Settings; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("Conversas")); tabLayout.addTab(tabLayout.newTab().setText("Contatos")); tabLayout.setTextAlignment(TextView.TEXT_ALIGNMENT_TEXT_END); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); final PagerAdapter adapter = new PagerAdapter (getSupportFragmentManager(), tabLayout.getTabCount()); viewPager.setAdapter(adapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { return false; } } package brliberty.com.tecner.www.liberty; /** * Created by karla on 27/10/15. */ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import brliberty.com.tecner.www.liberty.view.Settings; public class HistoricoConversas extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.historico_conversas, container, false); } @Override public void onCreate(Bundle savedInstanceState) { setHasOptionsMenu(true); super.onCreate(savedInstanceState); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.historicoconversa, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { Log.d("onOptionsItemSelected", "yes"); switch (item.getItemId()) { case R.id.search: Intent intent = new Intent(getActivity().getBaseContext(), Search_talking.class); startActivity(intent); return true; case R.id.ballon: intent = new Intent(getActivity().getBaseContext(), Talking.class); startActivity(intent); return true; case R.id.action_settings: intent = new Intent(getActivity().getBaseContext(), Settings.class); startActivity(intent); return true; default: break; } return false; } } package brliberty.com.tecner.www.liberty; /** * Created by karla on 27/10/15. */ import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; public class Contatos extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.contatos, container, false); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.contatos, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { Log.d("onOptionsItemSelected", "yes"); switch (item.getItemId()) { case R.id.search: return false; case R.id.add_people: return false; case R.id.action_settings: return false; default: return false; } } }
12/12/2017
Réulison Silva
Clique aqui para fazer login e interagir na Comunidade :)