How to add Toolbar and Viewpager in the same Layout

Asked

Viewed 94 times

0

When adding both components in layout XML I get the following error in the Viewpager starting line:

error: Error parsing XML: unbound prefix

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/br.com.pixells.simuladorbr"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <android.support.v7.widget.Toolbar
		xmlns:android="http://schemas.android.com/apk/res/android"
		android:id="@+id/toolbarListaJogos"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:background="#DC143C"
		app:subtitle="Teste"
		app:theme="@style/Theme.Abar.Widget"
		app:title="ToolBar" />
    
		<android.support.v4.view.ViewPager 
		    xmlns:android="http://schemas.android.com/apk/res/android"
			android:id="@+id/pager"  
			android:layout_width="match_parent"  
			android:layout_height="match_parent"  
			tools:context=".MainActivity" >  
		
		
		  
<!--  
This title strip will display the currently visible page title, as well as the page  
titles for adjacent pages.  
-->  
		  
			<android.support.v4.view.PagerTitleStrip  
				android:id="@+id/pager_title_strip"  
				android:layout_width="match_parent"  
				android:layout_height="wrap_content"  
				android:layout_gravity="top"  
				android:background="#33b5e5"  
				android:paddingBottom="4dp"  
				android:paddingTop="4dp" 
				android:textColor="#fff" />  
		
		  
		</android.support.v4.view.ViewPager> 

</LinearLayout>

  • Did not fail to add the schema of tools (xmlns:tools="http://schemas.android.com/tools")?

  • It worked, because I need to add this line?

  • Why you need to add the reference to the namespace schema tools so the parser can interpret these tags.

1 answer

1


Just add the reference to the schema of namespace tools at the beginning of your xml. Just like the other schemas:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/br.com.pixells.simuladorbr"
    <!-- Adicione a linha abaixo -->
    xmlns:tools="http://schemas.android.com/tools

Such inclusion is necessary for the aapt be able to correctly interpret namespace tags tools.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.