Why Android is truncating my ActionBar title?

前端 未结 13 2058
Happy的楠姐
Happy的楠姐 2021-02-13 10:28

In my app, I change the title in the ActionBar from each fragment displayed. When I first start my apps, I got a list of requests, so my title is \"My requests (20)\".

T

13条回答
  •  醉话见心
    2021-02-13 11:12

    put setTitle() in onCreateOptionsMenu helps me to solve this problem.

    In your fragment add setHasOptionsMenu(true); in onCreateView(){}

    Then override onCreateOptionsMenu().

    Example:

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        // put getActivity in onCreateOptionsMenu will not return null
        if (getActivity() != null) {
            getActivity().setTitle(getResources().getString(R.string.Studies));
        }
    }
    

    Reference: How to display android actionbar title without truncation occurring

提交回复
热议问题