Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you're doing is correct. <code>Fragments</code> don't have access to the <code>ActionBar</code> APIs, so you have to call <code>getActivity</code>. Unless your <code>Fragment</code> is a static inner class, in which case you should create a <code>WeakReference</code> to the parent and call Activity.<code>getActionBar</code> from there.</p> <p>To set the title for your <code>ActionBar</code>, while using a custom layout, in your <code>Fragment</code> you'll need to call <code>getActivity().setTitle(YOUR_TITLE)</code>.</p> <p>The reason you call <code>setTitle</code> is because you're calling <code>getTitle</code> as the title of your <code>ActionBar</code>. <code>getTitle</code> returns the title for that <code>Activity</code>.</p> <p>If you don't want to get call <code>getTitle</code>, then you'll need to create a public method that sets the text of your <code>TextView</code> in the <code>Activity</code> that hosts the <code>Fragment</code>. </p> <p><strong>In your Activity</strong>:</p> <pre><code>public void setActionBarTitle(String title){ YOUR_CUSTOM_ACTION_BAR_TITLE.setText(title); } </code></pre> <p><strong>In your Fragment</strong>:</p> <pre><code>((MainFragmentActivity) getActivity()).setActionBarTitle(YOUR_TITLE); </code></pre> <p><strong>Docs:</strong></p> <p><a href="https://developer.android.com/reference/android/app/Activity.html#getTitle()"><code>Activity.getTitle</code></a></p> <p><a href="https://developer.android.com/reference/android/app/Activity.html#setTitle(java.lang.CharSequence)"><code>Activity.setTitle</code></a></p> <p>Also, you don't need to call <code>this.whatever</code> in the code you provided, just a tip.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload