我想从工具栏中删除不需要的标题



问题是我正在将这些文本视图从另一个布局膨胀到工具栏中,我将在下面提供它们的代码。我已经尝试了所有我能做的事情。它甚至没有以编程方式进行

这是代码,其中我膨胀该布局并设置自定义视图

    private DatabaseReference mRootRef;
private FirebaseAuth mAuth;
private String mChatUser;
private String mCurrentUserId;
private Toolbar mChatToolbar;
private TextView mTitleView;
private TextView mLastSeenView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    mChatToolbar = (Toolbar) findViewById(R.id.chat_app_bar);
    setSupportActionBar(mChatToolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowCustomEnabled(true);
    mRootRef = FirebaseDatabase.getInstance().getReference();
    mAuth = FirebaseAuth.getInstance();
    mCurrentUserId = mAuth.getCurrentUser().getUid();
    mChatUser = getIntent().getStringExtra("user_id");
    String userName = getIntent().getStringExtra("user_name");
    LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View action_bar_view = inflater.inflate(R.layout.chat_custom_bar, null);
    actionBar.setCustomView(action_bar_view);
    // ---- Custom Action bar Items ----
    mTitleView = (TextView) findViewById(R.id.custom_bar_title);
    mLastSeenView = (TextView) findViewById(R.id.custom_bar_seen);

试试这个

getSupportActionBar().setDisplayShowTitleEnabled(false);

在清单声明时

<activity
    android:name="com.example.nikhil_pc.fritz.MainActivity"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.NoActionBar">

标签标签是工具栏标题。您可以将其从清单中删除onCreate也可以在方法调用setTitle(null)

最新更新