In Custom action bar if we hide any icon that space need to used by other icons or text view in action bar
<p>In my app I am using custom action bar. In that action bar I have 4 icons and 1 <code>textview</code>. For action bar I am using linear layout.</p>

<p>I have 4 activities in my app, each activity will have different action bar. If I open 1st activity one icon will set visibility gone. Every one of these activities will have different icons.</p>

<p>Question: My requirement is when icon is disable that space need to used by <code>textview</code>. I try everything but always space will end of the action bar I don't want that space.</p>

<p>Here is my code.</p>

<p><strong>MainActivity.class:-</strong>  </p>

<pre><code>public class MainActivity extends AppCompatActivity {

    ImageView Image1,Image2,Image3,Image4;
    TextView title;
    Button btn1,btn2,btn3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_main);
        /*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
*/
        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setCustomView(R.layout.custom_actionbar);

        View view = getSupportActionBar().getCustomView();

        Image1=(ImageView)findViewById(R.id.cst_ok);
        Image2=(ImageView)findViewById(R.id.cst_del);
        Image3=(ImageView)findViewById(R.id.cst_edt);
        Image4=(ImageView)findViewById(R.id.cst_srh);
        title=(TextView)findViewById(R.id.cst_txt);

        Image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdailog();
            }
        });

        btn1=(Button)findViewById(R.id.btn1);
        btn2=(Button)findViewById(R.id.btn2);
        btn3=(Button)findViewById(R.id.btn3);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1=new Intent(MainActivity.this,first_activity.class);
                startActivity(intent1);
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2=new Intent(MainActivity.this,second_activity.class);
                startActivity(intent2);
            }
        });
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent3=new Intent(MainActivity.this,third_activity.class);
                startActivity(intent3);
            }
        });
 private void showdailog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        LayoutInflater inflater = this.getLayoutInflater();
        final View dialogView = inflater.inflate(R.layout.custom_dialog, null);
        dialogBuilder.setView(dialogView);

        final EditText edt = (EditText) dialogView.findViewById(R.id.edit1);

        dialogBuilder.setTitle("Custom dialog");
        dialogBuilder.setMessage("Enter text below");
        dialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

//                et1.setText(edt.getText());
                title.setText(edt.getText());

            }
        });
        dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                //pass
            }
        });
        AlertDialog b = dialogBuilder.create();
        b.show();
    }
}
</code></pre>

<p><strong>FirstActivity.class:-</strong></p>

<pre><code>public class first_activity extends AppCompatActivity {

    ImageView Image1,Image2,Image3,Image4;
    TextView title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment1);

        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setCustomView(R.layout.custom_actionbar);

        View view = getSupportActionBar().getCustomView();

        Image1=(ImageView)view.findViewById(R.id.cst_ok);
        Image2=(ImageView)view.findViewById(R.id.cst_del);
        Image3=(ImageView)view.findViewById(R.id.cst_edt);
        Image4=(ImageView)view.findViewById(R.id.cst_srh);
        title=(TextView)view.findViewById(R.id.cst_txt);

        Image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdailog();
            }
        });

        Image3.setVisibility(View.GONE);
    }

    private void showdailog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        LayoutInflater inflater = this.getLayoutInflater();
        final View dialogView = inflater.inflate(R.layout.custom_dialog, null);
        dialogBuilder.setView(dialogView);

        final EditText edt = (EditText) dialogView.findViewById(R.id.edit1);

        dialogBuilder.setTitle("Custom dialog");
        dialogBuilder.setMessage("Enter text below");
        dialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

//                et1.setText(edt.getText());
                title.setText(edt.getText());

            }
        });
        dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                //pass
            }
        });
        AlertDialog b = dialogBuilder.create();
        b.show();
    }
}
</code></pre>

<p><strong>SecondActivity.class:-</strong></p>

<pre><code>public class second_activity extends AppCompatActivity {

    ImageView Image1,Image2,Image3,Image4;
    TextView title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment3);

        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setCustomView(R.layout.custom_actionbar);

        View view = getSupportActionBar().getCustomView();

        Image1=(ImageView)view.findViewById(R.id.cst_ok);
        Image2=(ImageView)view.findViewById(R.id.cst_del);
        Image3=(ImageView)view.findViewById(R.id.cst_edt);
        Image4=(ImageView)view.findViewById(R.id.cst_srh);
        title=(TextView)view.findViewById(R.id.cst_txt);

        Image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdailog();
            }
        });

        Image4.setVisibility(View.GONE);
    }

    private void showdailog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        LayoutInflater inflater = this.getLayoutInflater();
        final View dialogView = inflater.inflate(R.layout.custom_dialog, null);
        dialogBuilder.setView(dialogView);

        final EditText edt = (EditText) dialogView.findViewById(R.id.edit1);

        dialogBuilder.setTitle("Custom dialog");
        dialogBuilder.setMessage("Enter text below");
        dialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

//                et1.setText(edt.getText());
                title.setText(edt.getText());

            }
        });
        dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                //pass
            }
        });
        AlertDialog b = dialogBuilder.create();
        b.show();
    }
}
</code></pre>

<p><strong>ThirdActivity.class:-</strong></p>

<pre><code>public class third_activity extends AppCompatActivity {

    ImageView Image1,Image2,Image3,Image4;
    TextView title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment2);

        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setCustomView(R.layout.custom_actionbar);

        View view = getSupportActionBar().getCustomView();

        Image1=(ImageView)view.findViewById(R.id.cst_ok);
        Image2=(ImageView)view.findViewById(R.id.cst_del);
        Image3=(ImageView)view.findViewById(R.id.cst_edt);
        Image4=(ImageView)view.findViewById(R.id.cst_srh);
        title=(TextView)view.findViewById(R.id.cst_txt);

        Image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdailog();
            }
        });

        Image2.setVisibility(View.GONE);
    }

    private void showdailog() {
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        LayoutInflater inflater = this.getLayoutInflater();
        final View dialogView = inflater.inflate(R.layout.custom_dialog, null);
        dialogBuilder.setView(dialogView);

        final EditText edt = (EditText) dialogView.findViewById(R.id.edit1);

        dialogBuilder.setTitle("Custom dialog");
        dialogBuilder.setMessage("Enter text below");
        dialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

//                et1.setText(edt.getText());
                title.setText(edt.getText());

            }
        });
        dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                //pass
            }
        });
        AlertDialog b = dialogBuilder.create();
        b.show();
    }
}
</code></pre>

<p><strong>Custom_Actionbar_layout:-</strong></p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="40dp"
    android:weightSum="5"&gt;
&lt;ImageView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:src="@drawable/ok"
    android:id="@+id/cst_ok"/&gt;
    &lt;TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="Custom ActionBar"
        android:id="@+id/cst_txt"
        android:singleLine="false"
        android:maxLines="2"/&gt;
    &lt;ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/delete1"
        android:id="@+id/cst_del"/&gt;
    &lt;ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/edit"
        android:id="@+id/cst_edt"/&gt;
    &lt;ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/search"
        android:id="@+id/cst_srh"/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<blockquote>
  <p>And my theme is  <code>&lt;style name="AppTheme" parent="Theme.AppCompat.Light"&gt;</code></p>
  
  <p>And text view is dynamically changed text it is given by user. If any one need more details I will update.</p>
</blockquote>