android - toolbar layout is undefined -
i learning how use viewpager actiontabs through tutorial, , main layout hosts toolbar, tablayout , viewpager posted below in act_main.xml. @ run time receive below posted logcat errors , line 21 in posted xml layout contains
<android.support.v7.widget.toolbar
how fix it
main activitiy class:
public class mainactivity extends appcompatactivity { private final string tag = this.getclass().getsimplename(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.w(tag, "oncreate()"); setcontentview(r.layout.act_main); }
act_main.xml
<relativelayout android:id="@+id/main_layout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:background="?attr/colorprimary" android:elevation="6dp" android:minheight="?attr/actionbarsize" android:theme="@style/themeoverlay.appcompat.dark.actionbar" app:popuptheme="@style/themeoverlay.appcompat.light"/> <android.support.design.widget.tablayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/toolbar" android:background="?attr/colorprimary" android:elevation="6dp" android:minheight="?attr/actionbarsize" android:theme="@style/themeoverlay.appcompat.dark.actionbar"/> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_below="@id/tab_layout"/> </relativelayout>
gradle:
apply plugin: 'com.android.application' android { compilesdkversion 23 buildtoolsversion "23.0.2" defaultconfig { applicationid "com.example.com.vpager_00" minsdkversion 21 targetsdkversion 23 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.1.1' }
logcat:
fatal exception: main 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: process: com.example.com.vpager_00, pid: 23204 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: java.lang.runtimeexception: unable start activity componentinfo{com.example.com.vpager_00/com.example.com.vpager_00.mainactivity}: android.view.inflateexception: binary xml file line #21: error inflating class android.support.design.widget.tablayout 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.app.activitythread.performlaunchactivity(activitythread.java:2689) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.app.activitythread.handlelaunchactivity(activitythread.java:2754) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.app.activitythread.access$900(activitythread.java:177) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.app.activitythread$h.handlemessage(activitythread.java:1448) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.os.handler.dispatchmessage(handler.java:102) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.os.looper.loop(looper.java:145) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ android.app.activitythread.main(activitythread.java:5938) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ java.lang.reflect.method.invoke(native method) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ java.lang.reflect.method.invoke(method.java:372) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1400) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1195) 02-08 13:59:35.031 23204-23204/com.example.com.vpager_00 e/androidruntime: caused by: android.view.inflateexception: binary xml file line #21: error inflating class android.support.design.widget.tablayout
add google design library import dependencies {}
compile 'com.android.support:design:23.1.1'
you need add v4 support library
compile 'com.android.support:support-v4:23.1.1'
to prevent similar error <android.support.v4.view.viewpager />
your app.gradle
's dependencies {}
should this:
dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:support-v4:23.1.1' }
Comments
Post a Comment