Collapsing toolbar not showing Title Text - java

I'm facing a weird issue related to Collapsing toolbar. When I rotate the screen, the collapsing toolbar hides the toolbar title when the collapsing toolbar is contracted.
The toolbar title shows up when the collapsing toolbar is expanded
Please screen the screenshots here: https://imgur.com/a/99msG
<?xml version="1.0" encoding="utf-8"?>
<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="#dimen/collapsing_toolbar_title_margin_end"
app:expandedTitleMarginStart="#dimen/collapsing_toolbar_title_margin_start"
app:expandedTitleTextAppearance="#style/CollapsedAppBarTextAppearance"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#drawable/world_image"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?android:attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/list_countries"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_color"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Java code:
public class CountryListFragment extends Fragment {
#BindView(R.id.list_countries)
RecyclerView mCountriesListRecyclerView;
#BindView(R.id.toolbar)
Toolbar mToolbar;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_countries_list, container, false);
//must bind for View Injection
ButterKnife.bind(this, view);
// register event bus to receive events
EventBus.getDefault().register(this);
((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
initRecyclerView();
populateRecyclerViewAdapter();
return view;
}
}
From the looks of it, the collapsing toolbar gets confused about the orientation of the device and animates the toolbar downwards instead of animating it upwards.

Related

How to put custom toolbar inside fragment?

I created custom toolbar inside fragment,but i got view like this:
In themes.xml i disabled ActionBar:
<style name="Theme.Project" parent="Theme.MaterialComponents.DayNight.NoActionBar">
This is my custom toolbar layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
>
<TextView
android:id="#+id/toolbar_title"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Home"
android:fontFamily="#font/google_sans"
android:textColor="#color/black"
android:textSize="20sp" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/fragment_home" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
And this is HomeFragment.java:
public class HomeFragment extends Fragment {
private HomeViewModel homeViewModel;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
homeViewModel =
new ViewModelProvider(this).get(HomeViewModel.class);
View root = inflater.inflate(R.layout.toolbar_in_home, container, false);
return root;
}
}
How to remove this white thing on top of screen?
UPD:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".ui.home.HomeFragment">
</androidx.constraintlayout.widget.ConstraintLayout>
This is fragment home(just ConstraintLayout)
UPD2:i also was trying use toolbar in activity_main and it works:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.toolbar);
BottomNavigationView navView = findViewById(R.id.nav_view);
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_home, R.id.navigation_examination, R.id.navigation_profile)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupWithNavController(navView, navController);
}
But i can't do changes if i want to go on other fragment.
I need to set another custom toolbar layout with button like this:
So this is how I did it. My app is based on single activity-multi-fragment model.
I had set activity theme to AppTheme.NoActionBar, so it enabled me to set a custom toolbar.
Later for each fragment I had a separate layout and within which added a custom toolbar like below
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary">
....
....
</androidx.appcompat.widget.Toolbar>
Within this layout I had added menu items.
If you don't want to follow this, may be you should look at getActionBar().setCustomView(). Keep your activity theme set, so getActionBar() is not null.
You can control action bar layout by calling getActionBar().setCustomView() in fragment onResume() or probably when you are adding or removing a fragment in your activity.
You can use your custom toolbar inside the main layout replace it from com.google.android.material.appbar.AppBarLayout.
Here is an example code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="#color/colorPrimary">
<ImageView
android:id="#+id/navi"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:layout_centerInParent="true"
android:layout_marginStart="20dp"
android:contentDescription="#string/todo"
android:src="#drawable/navi" />
<ImageView
android:layout_width="180dp"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:contentDescription="#string/todo"
android:src="#drawable/header2" />
</RelativeLayout>
<include layout="#layout/fragment_home" />
</RelativeLayout>

Fragment not showing in home activity

I added navigation drawer on map activity. Now I'm trying to add a fragment on my home activity, but fragment is not showing in activity, but code in fragment class is working.
Is my FrameLayout hiding behind the map fragment?
I'm very new to fragments.
Please help me.
Home class layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="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:id="#+id/constrain_layout"
android:orientation="vertical">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintHorizontal_bias="0.0"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
map:layout_constraintVertical_bias="0.0"
tools:context=".HomeActivity" />
</androidx.constraintlayout.widget.ConstraintLayout>
Fragment class
public class RideHistory extends Fragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
Toast.makeText(getActivity(), "Ride History", Toast.LENGTH_SHORT).show();
View view = inflater.inflate(R.layout.fragment_ride_history,container,false);
return view;
}
}
Fragment xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".Fragments.RideHistory">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Ride History" />
</FrameLayout>
Change layout constraints so that both widgets frame layout and map fragment do not overlap eachother.
for ex:
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
map:layout_constraintBottom_toTopOf="#+id/map"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="434dp"
android:layout_height="297dp"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintHorizontal_bias="0.0"
map:layout_constraintStart_toStartOf="parent"
tools:context=".HomeActivity" />

Activity behind DialogFragment still accepts touches

I have the following DialogFragment
public class DetailItemFragment extends AppCompatDialogFragment {
#BindView(R.id.task_detail_name)
AppCompatTextView taskDetailNameText;
#BindView(R.id.task_detail_description)
AppCompatTextView taskDetailDescriptionText;
#BindView(R.id.task_detail_priority)
AppCompatTextView taskDetailPriorityText;
#BindView(R.id.toolbar)
Toolbar toolbar;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(true); //doesn't work
dialog.setCancelable(true); //doesn't work
return dialog;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_detail_view, container, false);
ButterKnife.bind(this, view);
//Get the Json back and parse it as a Task
Bundle bundle = getArguments();
final String taskAsJson = bundle.getString("task");
Task task = new Gson().fromJson(taskAsJson, Task.class);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.close);
}
setHasOptionsMenu(false);
taskDetailNameText.setText(task.getName());
taskDetailDescriptionText.setText(task.getDescription());
taskDetailPriorityText.setText(task.getPriority().toString());
return view;
}
I perform the Fragment transaction like so
//Put the clicked item into a Bundle for the next fragment to consume
DialogFragment detailItemFragment = new DetailItemFragment();
Bundle args = new Bundle();
args.putString("task", new Gson().toJson(mTaskListAdapter.getItem(position)));
detailItemFragment.setArguments(args);
getActivity().getSupportFragmentManager().beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.add(R.id.task_detail_fragment_container, detailItemFragment)
.addToBackStack(null)
.commit();
I'm trying to accomplish the following:
* On a tablet/large screen, this displays as a Dialog popup
* On a phone, it will display a fullscreen dialog (pretty much trying to replicate how Google Calendar handles opening event details)
This is what my xlarge/activity_main.xml looks like
<?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"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/task_detail_fragment_container"
android:layout_width="800dp"
android:layout_height="400dp"
android:layout_centerInParent="true"
android:elevation="16dp" />
<android.support.design.widget.AppBarLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/ToolbarStyle"
android:background="#color/colorPrimary"
app:title="#string/app_name"
app:titleTextColor="#color/white" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/task_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="#dimen/fab_normal_size"
android:layout_height="#dimen/fab_normal_size"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="#dimen/fab_padding"
android:layout_marginEnd="#dimen/fab_padding"
android:src="#drawable/add_black"
app:elevation="#dimen/fab_elevation"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="#dimen/fab_pressed_elevation" />
</RelativeLayout>
You'll notice I have a FrameLayout that is centered on the screen for loading the DetailItemFragment into. Maybe this isn't the correct way to do this--but I want to bring it up in case that turns out to be the issue.
This is what the fragment_detail_view.xml layout looks like
<android.support.design.widget.CoordinatorLayout 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/task_detail_background"
android:clickable="true"
android:elevation="8dp"
tools:context="io.havoc.todo.view.fragments.DetailItemFragment">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_tall_height"
android:background="?attr/colorPrimary">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/task_detail_name"
style="#style/TextAppearance.Widget.AppCompat.Toolbar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:gravity="start|bottom"
android:padding="8dp"
android:text="Task detail"
android:textColor="#color/white"
android:textSize="24sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginStart="86dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.AppCompatTextView
style="#style/TextAppearance.AppCompat.Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_margin"
android:text="#string/hint_task_description"
android:textColor="#color/colorAccent" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/task_detail_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Description text"
android:textColor="#color/text_primary"
android:textSize="18sp" />
<android.support.v7.widget.AppCompatTextView
style="#style/TextAppearance.AppCompat.Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_margin"
android:text="#string/hint_task_priority"
android:textColor="#color/colorAccent" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/task_detail_priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Priority"
android:textColor="#color/text_primary"
android:textSize="18sp" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
The issue
When the DialogFragment is open on a tablet, the Activity in the background still accepts touches (i.e. I can interact with the Activity as if the dialog wasn't even present); furthermore, I have no idea how to get the DialogFragment to dismiss when touching outside of it. I've tried the following:
dialog.setCanceledOnTouchOutside(true); (in the onCreateDialog() method)
dialog.setCancelable(true); (in the onCreateDialog() method)
dialog.setCanceledOnTouchOutside(false); (in the onCreateDialog() method)
getDialog().setCanceledOnTouchOutside(true); setCancelable(true); (leads to NullPointerExceptions--performed in onCreateView() for the DialogFragment)
I've gone through all the other questions like this I could find and nothing has worked for me--so clearly I'm doing something wrong.
I appreciate any and all help.
Change to .dialog.setCancelable(false);.
If it's a dialog with OK and Cancel buttons, you can use:
.setCancelable(closeActivity == true ? false : true)
The FrameLayout (task_detail_fragment_container) you are adding your DetailItemFragment TO has a different size then the parent, which means it will not cover the entire layout:
...
android:layout_width="800dp"
android:layout_height="400dp"
...
To fix this, make task_detail_fragment_container the same size as the parent layout (match_parent) and cap the size of the dialog in the dialog layout by introducing another Layout after your container layout:
<android.support.design.widget.CoordinatorLayout 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:clickable="true"
android:elevation="8dp"
tools:context="io.havoc.todo.view.fragments.DetailItemFragment">
<FrameLayout
andorid:width="800dp"
android:height="400dp"
android:layout_centerInParent="true">
<android.support.design.widget.AppBarLayout ...
//rest of your xlm here
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Change this
dialog.setCanceledOnTouchOutside(true);
with
dialog.setCanceledOnTouchOutside(false);

Toolbar not showing up?

I am trying to implement a toolbar in my activity but it doesn't seem to work. My MainActivity is a ViewPager, which contains Fragments 1 and 2. I tried to implement my toolbar directly into the Viewpager, this didn't work so instead I tried to wrap my Viewpager in a RelativeLayout and include the toolbar in that RelativeLayout, but this also doesn't work.
The layout for my toolbar (app_bar.xml):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/app_bar"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:theme="#style/CustomToolBarStyle"
android:title="Something"
android:logo="#drawable/ic_launcher">
</android.support.v7.widget.Toolbar>
this is how I've implemented the toolbar in my activity (activity_main.xml):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="#+id/app_bar" layout="#layout/app_bar"/> <-----------
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</android.support.v4.view.ViewPager>
</RelativeLayout>
and this is what I've done in my activity's Java file to set the toolbar as the actionbar (MainActivity.java):
public class MainActivity extends AppCompatActivity {
ViewPager pager;
android.support.v4.app.FragmentManager fragmentManager;
FloatingActionButton fab;
Toolbar tb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (ViewPager) findViewById(R.id.pager);
fab = (FloatingActionButton) findViewById(R.id.fab_main);
tb = (Toolbar) findViewById(R.id.app_bar);
fragmentManager = getSupportFragmentManager();
pager.setAdapter(new myAdapter(fragmentManager));
AdView mAdView = (AdView) findViewById(R.id.adView);
//AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice("YOUR_DEVICE_HASH")
//.build();
//do not make visible while testing!!
//mAdView.loadAd(adRequest);
setSupportActionBar(tb); <------------------
it would really appreciate it if someone is able to help me out. Have a nice day!
Vidal
Try to remove id from include tag and add android:layout_below="#+id/app_bar" to your ViewPager.
Change your toolbar height from wrap_content to you ?attr/actionBarSize as shown below:
app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/app_bar"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/CustomToolBarStyle"
android:title="Something"
android:logo="#drawable/ic_launcher">
</android.support.v7.widget.Toolbar>
and position your viewpager below Toolbar as shown below
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="#+id/app_bar" layout="#layout/app_bar"/>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/pager"
android:layout_below="#id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Hope this helps!

Black/Blank Screen when app is opened

I have successfully implemented Google's SlidingTabLayout and it is working as expected but my view is showing a black screen below it. Like so:
Here is the my activity main layout folder:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation= "16dp">
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:id = "#+id/stickylist">
<ViewFlipper
android:id="#+id/flipper1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:flipInterval="2000"
android:inAnimation="#android:anim/fade_in"
android:outAnimation="#android:anim/fade_out"
>
<ImageView
android:src="#drawable/front"
android:layout_width="220dp"
android:layout_height="180dp"
android:contentDescription="#string/str_img1"
/>
<ImageView
android:src="#drawable/field"
android:layout_width="220dp"
android:layout_height="180dp"
android:contentDescription="#string/str_img2"
/>
<ImageView
android:src="#drawable/cafeteria"
android:layout_width="220dp"
android:layout_height="180dp"
android:contentDescription="#string/str_img3"
/>
</ViewFlipper>
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
android:id="#+id/left_drawer"
android:layout_width="220dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:divider="#drawable/customdrawershape"
/>
</LinearLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/fragment_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
Then here is where I implement my PagerAdapter in SlidingTabsBasicFragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.tabs, container, false);
....}
tabs.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<xxx.xxx.xxx.SlidingTabLayout
android:id="#+id/pager_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="16dp"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_weight ="1"
android:layout_height="0dp"
>
</android.support.v4.view.ViewPager>
</LinearLayout>
Here is where I call on the fragment in my activity class:
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.addToBackStack(null);
SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment();
transaction.replace(R.id.fragment_container, fragment);
transaction.commit();
I do have other simultaneous fragments ongoing from the main activity that should be displayed. Is that what is going on? Here is the code for that fragment using a different layout for both what is displayed as well as the frame layout for the fragment container.
manager = getChildFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.addToBackStack(null);
EventFragment fragment = new EventFragment();
transaction.add(R.id.fragment_container, fragment);
transaction.commit();
The fragment container for the view I am trying to display that is not showing is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/fragment_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</FrameLayout>
Here is the layout to the first fragment which uses a custom adapter for each list view tile integrated in from a different layout.
<RelativeLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:background="#drawable/background">
<TextView
android:id= "#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/string5"
android:layout_centerHorizontal="true"
android:layout_below= "#+id/progressBar"
android:textColor="#FFD600"
android:textSize="20sp"/>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:color="#42A5F5"
android:indeterminateTint="#42A5F5"
android:indeterminateTintMode="multiply"/>
<com.twotoasters.jazzylistview.JazzyListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView"
android:divider="#android:color/transparent"
android:dividerHeight="5dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_above="#+id/layout"/>
</RelativeLayout>
EDIT:
Ok now I can get it show the screen by doing the following:
#Override
public Object instantiateItem(ViewGroup container, int position) {
// Inflate a new layout from our resources
switch (position){
case 0:
view = getActivity().getLayoutInflater().inflate(R.layout.eventlistview,
container, false);
new Event();
break;
case 1:
view = getActivity().getLayoutInflater().inflate(R.layout.twitter,
container, false);
new Twitter();
break;
case 2:
view = getActivity().getLayoutInflater().inflate(R.layout.stafflistview,
container, false);
new Staff();
break;
case 3:
view = getActivity().getLayoutInflater().inflate(R.layout.powerschool,
container, false);
new powerschool();
break;
}
// Add the newly created View to the ViewPager
container.addView(view);
// Return the View
return view;
}
But eventually the progress bar for the fragment layout I have code for is supposed to go away and a list view is to be displayed. However, it will just show this layout forever even though there is more going on in the background. Any ideas?
This is so limited if all you can do is a single layout. Seriously? This is bad.
Wild guesses...
in your tabs.xml: your ViewPager has a weight of android:layout_weight ="1" and a height of android:layout_height="0dp" your slidingtablayout has a height of wrap_content and ther father has not weightsum.. Change their father's weightsum to 1 and see..
let me know if it helps

Categories

Resources