Skip to content Skip to sidebar Skip to footer

Icon Disappeared In Action Bar After Enabling A New Toolbar

I want to design a split action toolbar (I know that it was removed since android 5.0 lollipop). The below example showed me a new toolbar, but the icons on the action bar have now

Solution 1:

I think you can refer to the following sample (the activity_main.xml looks like the one I posted in your previous question, but now edited - adding buttons inside top toolbar)

<android.support.design.widget.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/AppTheme.AppBarOverlay"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:background="?attr/colorPrimary"app:popupTheme="@style/AppTheme.PopupOverlay"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"><ImageButtonandroid:id="@+id/button1a"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@android:color/transparent"android:src="@drawable/ic_action_cloud" /><ImageButtonandroid:id="@+id/button2a"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@android:color/transparent"android:src="@drawable/ic_action_copy" /></LinearLayout></android.support.v7.widget.Toolbar></android.support.design.widget.AppBarLayout><includelayout="@layout/content_main" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"><android.support.v7.widget.Toolbarandroid:id="@+id/toolbar_bottom"android:layout_width="match_parent"android:layout_height="?attr/actionBarSize"android:layout_alignParentBottom="true"android:background="?attr/colorPrimary"app:popupTheme="@style/AppTheme.PopupOverlay"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"><ImageButtonandroid:id="@+id/button1"android:layout_width="10dp"android:layout_height="wrap_content"android:layout_weight="0.175"android:background="@android:color/transparent"android:src="@drawable/ic_action_back" /><Viewandroid:id="@+id/view1"android:layout_width="0dp"android:layout_height="0dp"android:layout_weight="0.1" /><ImageButtonandroid:id="@+id/button2"android:layout_width="10dp"android:layout_height="wrap_content"android:layout_weight="0.175"android:background="@android:color/transparent"android:src="@drawable/ic_action_cloud" /><Viewandroid:id="@+id/view2"android:layout_width="0dp"android:layout_height="0dp"android:layout_weight="0.1"android:background="@android:color/transparent" /><ImageButtonandroid:id="@+id/button3"android:layout_width="10dp"android:layout_height="wrap_content"android:layout_weight="0.175"android:background="@android:color/transparent"android:src="@drawable/ic_action_copy" /><Viewandroid:id="@+id/view3"android:layout_width="0dp"android:layout_height="0dp"android:layout_weight="0.1"android:background="@android:color/transparent" /><ImageButtonandroid:id="@+id/button4"android:layout_width="10dp"android:layout_height="wrap_content"android:layout_weight="0.175"android:background="@android:color/transparent"android:src="@drawable/ic_action_help" /></LinearLayout></android.support.v7.widget.Toolbar></RelativeLayout>

Then in your activity:

publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener {
privatefinalContextmContext=this;

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbartoolbar= (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ImageButtonbutton1= (ImageButton) findViewById(R.id.button1);

    button1.setOnClickListener(this);
}

@OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    returntrue;
}

@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.intid= item.getItemId();

    //noinspection SimplifiableIfStatementif (id == R.id.action_settings) {
        Toast.makeText(mContext, "action_settings", Toast.LENGTH_SHORT).show();
        returntrue;
    }

    returnsuper.onOptionsItemSelected(item);
}

@OverridepublicvoidonClick(View view) {
    switch (view.getId()) {
        case R.id.button1:
            Toast.makeText(mContext, "button1", Toast.LENGTH_SHORT).show();
            break;
        default:
    }
}
}

Hope this helps!

Post a Comment for "Icon Disappeared In Action Bar After Enabling A New Toolbar"