I am trying to change the action bar properties of my activities but I am getting an error "Error inflating class toolbar".
Here is the code snippet :
import android.support.v7.widget.Toolbar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vendor_details);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Details");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Here is the Android Manifest code for that activity :
<activity
android:name=".VendorDetails"
android:label="VendorDetails"
android:theme="#style/AppTheme.NoActionBar"/>
And the layout code for the toolbar is :
<Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary">
</Toolbar>
Does anyone know how to solve it?
I am stuck on it since yesterday now. Thanks in advance.
Here is the full xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.sachinparashar.omitravendorassistance.Verify"
tools:showIn="#layout/activity_verify">
<TextView
android:layout_width="210dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter the Code sent"
android:id="#+id/verifyText"
android:padding="5dp"
android:layout_marginTop="32dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/userCode"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="120dp"
android:hint="Enter Code"
android:gravity="center_horizontal" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Verify"
android:id="#+id/verify"
android:layout_marginTop="100dp"
android:textStyle="bold|italic"
android:textSize="20dp"
android:layout_below="#+id/userCode"
android:layout_centerHorizontal="true"
android:onClick="onVerify" />
<Button
android:layout_width="110dp"
android:layout_height="wrap_content"
android:text="Resend"
android:id="#+id/resend"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/verify"
android:layout_centerHorizontal="true"
android:layout_marginTop="37dp"
android:onClick="onResend"
android:visibility="invisible" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="700dp"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/timer"
android:layout_below="#+id/userCode"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:textSize="25dp"
android:gravity="center_horizontal" />
You need to use Toolbar as below in xml.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
Related
I have list in viewpager and i have audio player on bottom. But my viewpager doesn't end the starting of audio player. I can't see my last 2 - 3 items in viewpager. And i don't wanna use MarginBottom.
some screenshots
my activity.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- AppBar Layout -->
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<!-- Tab Layout for creating tabs -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- Helps handing the Fragments for each Tab -->
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:layout_width="fill_parent"
android:layout_height="90dp"
android:layout_marginTop="5dp"
android:layout_below="#+id/viewPager"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_gravity="bottom"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<android.support.design.widget.NavigationView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:paddingLeft="10dp"
android:layout_gravity="center"
android:paddingRight="10dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/btnBackward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginBottom="4dp"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnBackward"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnBackward"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/btnPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPlay"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPlay"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPause"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPause"
android:contentDescription="#+id/imageButton3"
android:src="#android:drawable/ic_media_ff" />
<TextView
android:id="#+id/txtStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:text="0 min, 0 sec" />
<SeekBar
android:id="#+id/sBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btnBackward"
android:layout_toLeftOf="#+id/txtSongTime"
android:layout_toRightOf="#+id/txtStartTime" />
<TextView
android:id="#+id/txtSongTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:layout_toRightOf="#+id/btnForward"
android:text="0 min, 0 sec " />
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.CoordinatorLayout>
I tried a couple solution but none of them worked. Only solution i can find is using marginbottom, but i think that would be bad choices.
Any help would be great. Thanks.
You can solve this by wrapping the ViewPager and the BottomNavigationView within a ConstraintLayout and add a constraint so that the bottom part of the ViewPager should be at the top part of the BottomNavigationView using: app:layout_constraintBottom_toTopOf attribute at the ViewPager
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
...
app:layout_constraintBottom_toTopOf="#id/bottom_nav_view"
And then make the height of the ViewPager match the constraints instead of the fill_parent or match_parent
To apply this change your layout to:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- AppBar Layout -->
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
<!-- Tab Layout for creating tabs -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- Helps handing the Fragments for each Tab -->
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="#id/bottom_nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_nav_view"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_marginTop="5dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintBottom_toBottomOf="parent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<android.support.design.widget.NavigationView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageButton
android:id="#+id/btnBackward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="50dp"
android:layout_marginBottom="4dp"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/btnPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnBackward"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnBackward"
android:src="#android:drawable/ic_media_play" />
<ImageButton
android:id="#+id/btnPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPlay"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPlay"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/btnForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/btnPause"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#+id/btnPause"
android:contentDescription="#+id/imageButton3"
android:src="#android:drawable/ic_media_ff" />
<TextView
android:id="#+id/txtStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:text="0 min, 0 sec" />
<SeekBar
android:id="#+id/sBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btnBackward"
android:layout_toLeftOf="#+id/txtSongTime"
android:layout_toRightOf="#+id/txtStartTime" />
<TextView
android:id="#+id/txtSongTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/sBar"
android:layout_toRightOf="#+id/btnForward"
android:text="0 min, 0 sec " />
</RelativeLayout>
</android.support.design.widget.NavigationView>
</android.support.design.widget.BottomNavigationView>
</android.support.constraint.ConstraintLayout>
</android.support.design.widget.CoordinatorLayout>
Edit:
It's kind of worked. Bottom is fixed bot now i can't see Top, first 2 3 item under appBar. i tried couple of codes something like that app:layout_constraintBottom_toBottomOf="#id/appBarLayout" but doesn't worked.
Solution:
app:layout_constraintTop_toBottomOf="#+id/appBarLayout" and to gradle 'com.android.support.constraint:constraint-layout:1.0.2' now it's working.
I have this weird problem that I have no idea where it's coming from.
I am making recipes app and I am using SQLite to display image, description and favorite check box. For recipe instructions I am not using SQLite , instead I am using TextView.
In my app I have two activities BreakfastActivity and Breakfast2Activity with their layouts that displays content which I mentioned above.The problem is that Breakfast Activity's XML code overwrites BreakfastActivity2 layout.
Note: The information that coming from database does't overwrite , but the one that comes from xml does.
I checked java activities if they use same layouts and if the layouts use the same context. Everything seems fine. I can't figure out where it can be potential problem.
Any Help would be appreciated.
This is activity_breakfast xml.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".BreakfastActivity">
//I added shadow to the toolbar using design library
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//I referenced other layout (tool bar layout)
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_main" />
</android.support.design.widget.AppBarLayout>
<ImageView
android:id="#+id/photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:maxWidth="600dp"
android:maxHeight="300dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textSize="20dp"
android:textColor="#454444"
android:textStyle="bold"/>
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"/>
<TextView
android:id="#+id/instructionsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="Instructions"
android:paddingLeft="10dp"
android:textSize="20dp" />
<TextView
android:id="#+id/instructionsStepsCrepes1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsCrepesStep1"/>
<TextView
android:id="#+id/instructionsStepsCrepes2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsCrepesStep1"/>
<TextView
android:id="#+id/instructionsStepsCrepes3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsCrepesStep3"/>
<CheckBox
android:id="#+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/favorite"
android:layout_weight="2"
android:paddingLeft="10dp"
android:onClick="onFavoriteClicked"/>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/colorPrimaryDark"
app:itemTextColor="#color/colorPrimaryDark"
app:menu="#menu/bottom_nav_menu">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_navigation"
android:background="#drawable/shadow"/>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
</ScrollView>
This is BreakfastActivity.java
public class BreakfastActivity extends AppCompatActivity {
public static final String EXTRA_BREAKFASTID ="breakfastId";
private ShareActionProvider shareActionProvider;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast);
This is activity_breakfast2 xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".Breakfast2Activity">
//I added shadow to the toolbar using design library
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//I referenced other layout (tool bar layout)
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_main" />
</android.support.design.widget.AppBarLayout>
<ImageView
android:id="#+id/photoBreakfast2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:maxWidth="600dp"
android:maxHeight="300dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/nameBreakfast2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/descriptionBreakfast2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/instructionsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="Instructions"
android:paddingLeft="10dp"
android:textSize="20dp" />
<TextView
android:id="#+id/instructionsStepsOmellete1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsOmelleteStep1"/>
<TextView
android:id="#+id/instructionsStepsOmellete2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsOmelleteStep2"/>
<TextView
android:id="#+id/instructionsStepsOmellete3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsOmelleteStep3"/>
<CheckBox
android:id="#+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/favorite"
android:layout_weight="2"
android:onClick="onFavoriteClicked"/>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/colorPrimaryDark"
app:itemTextColor="#color/colorPrimaryDark"
app:menu="#menu/bottom_nav_menu" >
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_navigation"
android:background="#drawable/shadow"/>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.AppBarLayout>
this is ActivityBreakfast2.java
public class Breakfast2Activity extends AppCompatActivity {
public static final String EXTRA_BREAKFAST2ID = "BREAKFAST2Id";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast2);
I have a strange issue that i cannot solve, i have a little spacing between my settings bar and the toolbar, watch here
my xml for the toolbar:
<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"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
on activity i call it like this:
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
All Acitivity XML (put all my code in external file and include it)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true"
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="com.example.afcosta.inesctec.pt.android.FamilyLibrary"
android:paddingTop="6dp">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_menu_camera"
app:backgroundTint="#f1c40f"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="37dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="33dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/gallery"
android:layout_width="0dp"
android:layout_height="562dp"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="97dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<include
layout="#layout/custom_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/toolbar"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Familias"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toTopOf="#+id/gallery"
android:layout_marginStart="8dp"
tools:layout_constraintLeft_creator="1"
android:layout_marginBottom="15dp"
app:layout_constraintLeft_toLeftOf="parent"
android:textSize="24dp"/>
</android.support.constraint.ConstraintLayout>
it appears, but that strange white space is annoying :/
You have to remove padding from ConstraintLayout:
android:paddingTop="6dp"
I'm new to android so excuse me if I it is too obvious.
My first problem is with the FloatingActionButton. I basically only need on FloatingActionButton wich is to save the search, but there is another one that appears only when I run the app and not in the design view(nor text view).. where did that come from and how can I remove it ??
The XML file
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginTop="#dimen/fab_margin_top"
android:src="#drawable/ic_favorite_24dp"
android:contentDescription="#string/save_description"
android:layout_alignParentRight="true"
android:layout_alignParentStart="false"
android:layout_alignTop="#+id/tagTextInputLayout" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/URLTextInputLayout"
android:layout_below="#id/view"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:hint="#string/url_prompt"
android:singleLine="true"
android:layout_below="#+id/view"
android:layout_toRightOf="#+id/URLTextInputLayout"
android:layout_toEndOf="#+id/URLTextInputLayout" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tagTextInputLayout"
android:layout_below="#id/URLTextInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/tag_prompt"
android:imeOptions="actionDone" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/tagTextInputLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/tagged_links"
android:id="#+id/textView"
android:gravity="center_horizontal"
android:textStyle="bold"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="#+id/recyclerView"
android:layout_weight="1"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" />
</LinearLayout>
I am trying to create a layout with basically a head, body, and footer. The ViewPager I am using is filling the space behind the footer content though. How can I make it not do this, and cutoff at the start of the footer content?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.janedoe.anothertabexample.MainActivity"
tools:showIn="#layout/activity_main">
<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/tabLayout"
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/tabLayout"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp">
<TextView
android:id="#+id/time"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="00:00:00"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mileage"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="0.0 mi"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/time"
android:text="Start" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/mileage"
android:text="Stop" />
</RelativeLayout>
</RelativeLayout>
I don't want the color(which is just the content) to run past the Buttons and TextViews on the bottom. I've tried the layout_gravity method as well as setting the viewpager to layout_above and layout_blow but neither appear to work. How can I achieve this?
You view pager will consume all space available.
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/tabLayout"/>
I would try switching to a LinearLayout and use the "android:layout_weight" property to force the ViewPager to only use available space.
your RelativeLayout should have android:layout_alignParentBottom="true".
<RelativeLayout android:id="#+id/relativeFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp">
Remove android:layout_alignParentBottom="true" from all its child.
and your viewpager should look like below
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/relativeFooter"
android:layout_below="#id/tabLayout"/>
Finally your whole layout should be like below :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<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/tabLayout"
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_above="#+id/relativeFooter"
android:layout_below="#id/tabLayout"/>
<RelativeLayout android:id="#+id/relativeFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingBottom="5dp">
<TextView
android:id="#+id/time"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:gravity="center"
android:text="00:00:00"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/mileage"
android:layout_width="100dp"
android:layout_height="55dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="0.0 mi"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/time"
android:text="Start" />
<Button
android:layout_width="80dp"
android:layout_height="55dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#id/mileage"
android:text="Stop" />
</RelativeLayout>