How to put a subheading at the bottom of the app name in the bar menu

Asked

Viewed 414 times

1

inserir a descrição da imagem aqui

I’m willing to put two things on the bar menu, but I have no idea how you do that. Whatsapp has two things on the menu bar, the contact name and the time that viewed Whatsapp.

Is there any way I can do that? Have two names on the bar menu?

My Mainactivity class

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ViewPager galeria = (ViewPager) findViewById(R.id.galeria);
    GaleriaImagensAdapter adapter = null;
    try {
        adapter = new GaleriaImagensAdapter(this);
    } catch (SQLException e) {
        e.printStackTrace();
    }
    galeria.setAdapter(adapter);
}

There at the time of setting the image I was wanting to change the title and subtitle, using this setTitle and setSubtitle, has as?

Here I put the image

@Override
public Object instantiateItem(ViewGroup pager, int position) {
    ImageView imagem = new ImageView(context);
    imagem.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

    try {
        Class res = R.drawable.class;
        Field field = res.getField(itens.get(position).nome_foto);
        int drawableId = field.getInt(null);
        imagem.setImageResource(drawableId);
    }
    catch (Exception e) {
        Log.e("MyTag", "Failure to get drawable id.", e);
    }
    ((ViewPager) pager).addView(imagem, 0);
    return imagem;
}
  • By "wpp" you meant "Whatsapp"?

  • To ActionBar has a setTitle and setSubtitle. That’s what you mean?

  • I’m wanting to do that image, but I don’t know how. This setSubtitle should work. how do I use it? Luidne and yes , shorthand

  • Well, what has on Whatsapp is different than what you showed in the image. Whatsapp uses the ActionBar Android with a title and subtitle, which is simple. This image is something even more personalized.

  • the image and to illustrate , I just need to have these two information

2 answers

1

In his Activity, use the code below to define the title and subtitle, if you are using ActionBar:

getActionBar.setTitle("Título");
getActionBar.setSubtitle("Subtítulo");

Or getSupportActionBar if using the compatibility library.

1


For this you must register a listener for when the ViewPager change you capture the event and do something related.

It can be done like this:

ViewPager galeria = (ViewPager) findViewById(R.id.galeria);
galeria.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageSelected(int position) {
        getActionBar().setTitle("Posição "+position);
        getActionBar().setSubtitle("Posição "+position);

        // Para biblioteca de compatibilidade
        //getSupportActionBar().setTitle("Posição "+position);
        //getSupportActionBar().setSubtitle("Posição "+position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }
});

To change according to the Adapter you can also create a method to search for it by passing the received position on onPageSelected() and then change its title and subtitle immediately.

  • It has how to center the text?

  • Yes, have a look at that answer: http://stackoverflow.com/a/26548766/3618148

Browser other questions tagged

You are not signed in. Login or sign up in order to post.