android - Toolbar in non-AppCompat project not inflating -


i tried implement toolbar activity it's not inflating , keeps showing error. project not use appcompat i'm not sure whether or not vause of error.

error inflating class android.widget.toolbar

java

public class mainactivity extends activity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          toolbar customtoolbar = findviewbyid(r.id.toolbar_1line);         setactionbar(customtoolbar);          //add arrow toolbar         if (getactionbar() != null){             getactionbar().setdisplayhomeasupenabled(true);             getactionbar().setdisplayshowhomeenabled(true);         }          textview mtitle = this.findviewbyid(r.id.toolbar_title);         mtitle.settext(getstring(r.string.select_a_destination_station));         mtitle.settextcolor(color.white);         mtitle.setellipsize(textutils.truncateat.marquee);         mtitle.setmarqueerepeatlimit(-1);         mtitle.setsingleline(true);         mtitle.setselected(true);     } } 

toolbar layout

<?xml version="1.0" encoding="utf-8"?> <android.widget.toolbar     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/toolbar_1line"     android:layout_width="match_parent"     android:layout_height="?android:attr/actionbarsize"     android:minheight="?android:attr/actionbarsize">      <linearlayout         android:id="@+id/singleline_text_layout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="center_vertical"         android:orientation="vertical">          <textview             android:id="@+id/toolbar_title"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             style="@android:style/textappearance.material.widget.actionbar.title"/>     </linearlayout> </android.widget.toolbar> 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/detail_container">      <include layout="@layout/toolbar_singleline"         android:layout_width="match_parent"         android:layout_height="wrap_content"/>      <listview         android:id="@+id/list_objects"         android:layout_width="match_parent"         android:layout_height="wrap_content" />  </linearlayout> 

try this.

in toolbar_layout

one way

change

<android.widget.toolbar     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/toolbar_1line"     android:layout_width="match_parent"     android:layout_height="?android:attr/actionbarsize"     android:minheight="?android:attr/actionbarsize"> </android.widget.toolbar> 

to

<android.support.v7.widget.toolbar     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/toolbar_1line"     android:layout_width="match_parent"     android:layout_height="?android:attr/actionbarsize"     android:background="?attr/colorprimary"     android:minheight="?android:attr/actionbarsize"> </android.support.v7.widget.toolbar> 

in java code

change

toolbar customtoolbar = findviewbyid(r.id.toolbar_1line); setactionbar(customtoolbar);  //add arrow toolbar if (getactionbar() != null){     getactionbar().setdisplayhomeasupenabled(true);     getactionbar().setdisplayshowhomeenabled(true); } 

to

toolbar customtoolbar = (toolbar) findviewbyid(r.id.toolbar_1line); setsupportactionbar(customtoolbar); //add arrow toolbar if (getsupportactionbar() != null) {     getsupportactionbar().setdisplayhomeasupenabled(true);     getsupportactionbar().setdisplayshowhomeenabled(true); } 

another way

change

<android.widget.toolbar     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/toolbar_1line"     android:layout_width="match_parent"     android:layout_height="?android:attr/actionbarsize"     android:minheight="?android:attr/actionbarsize"> </android.widget.toolbar> 

to

<toolbar     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/toolbar_1line"     android:layout_width="match_parent"     android:layout_height="?android:attr/actionbarsize"     android:background="?attr/colorprimary"     android:minheight="?android:attr/actionbarsize"> </toolbar> 

it's easy.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -