android - How do i add my action bar to my view class? -


how add action bar view(canvas) class?

public class mainactivity extends appcompatactivity {   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);       this.requestwindowfeature(window.feature_no_title);     this.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen);       //set paint color      setcontentview(r.layout.activity_main);     //setcontentview(new drawview(this));       toolbar toolbar = (toolbar) findviewbyid(r.id.my_toolbar);     setsupportactionbar(toolbar);     //drawview.setpaint(255, 235, 191, 47); } 

here project.

here project , tool bar stored in activity_main.xml.

visual representation of want :p left screen shot when use setcontentview(r.layout.activity_main);, right 1 //setcontentview(new drawview(this)); enter image description here

thanks guys! , if ok can guys incl. explanation well? i'm new android programming :)

activity_main xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.example.nikol.touchpaint.mainactivity"> <!--    <view         android:id="@+id/viewid"         android:layout_width="match_parent"         android:layout_height="match_parent" />-->      <android.support.v7.widget.toolbar         android:id="@+id/my_toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionbarsize"         android:background="?attr/colorprimary"         android:elevation="4dp"         android:theme="@style/themeoverlay.appcompat.actionbar"         android:popuptheme="@style/themeoverlay.appcompat.light"/>      <textview         android:id="@+id/testtext"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentstart="true"         android:layout_marginbottom="151dp"         android:text="hello world!" />      <button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_aligntop="@+id/button2"         android:layout_tostartof="@+id/button2"         android:text="new button" />      <button         android:id="@+id/button2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true"         android:layout_marginbottom="29dp"         android:layout_marginend="30dp"         android:text="new button" />  </relativelayout> 

in layout editor view toolbar, , buttons, scroll down in editor see "custom view".

from there, can start typing, , can add custom view class , add wherever in xml want.

custom view


Comments