Center title of activity in android action bar

前端 未结 3 1190
独厮守ぢ
独厮守ぢ 2021-01-15 09:56

Right now the title of my activity shows to the left as < Title and then the other menu item shows to the right. I want to center my title and leave out the

3条回答
  •  误落风尘
    2021-01-15 10:52

    I also used actionbar sherlock and i set header position by this method. you can set a custom textview and can set its gravity to center. use the below method and tell me.

        private void setHeader(){
        LayoutInflater linflater = (LayoutInflater)MainAccountActivity.context.getSystemService(MainAccountActivity.context.LAYOUT_INFLATER_SERVICE);
        View GalleryTitleView = linflater.inflate(R.layout.layout_header, null);
    
        galleryTitleTv = (TextView) GalleryTitleView
                .findViewById(R.id.GalleryTitleTv);
        galleryTitleTv.setText(ITWAppUIConstants.TAB_AGENDA);
    
        ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.FILL_PARENT,
                ActionBar.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
        GalleryTitleView.setLayoutParams(lp);
        getSupportActionBar().setCustomView(GalleryTitleView);
      }
    

    and here is the layout i used:

      
    
    
    
    

提交回复
热议问题