android


Why tablayout and actionbar put space in fragment in android?


Explanation:
I implemented a navigationDrawer in Activity.There are lot off fragment are available.I used a materialDesign them for my application.
When i put tablayout in activity it's not putting space. When i put tablayout inside one of my fragment it put the space between my toolbar and tablayout.
Here is my fragment.xml
<?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-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/main_background"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#drawable/gradient"
android:theme="#style/MyMaterialTheme.AppBarOverlay" >
<android.support.design.widget.TabLayout
android:id="#+id/tabs_schedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabTextColor="#color/tab_text"
app:tabSelectedTextColor="#color/tab_text"
app:tabIndicatorColor="#E15E5E"
app:tabIndicatorHeight="3dp"
app:tabTextAppearance="#style/MyTabLayoutTextAppearance"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
Here is my fragment.java
public class ScheduleSpinner extends Fragment {
View rootView;
TabLayout tabLayout;
ViewPager viewPager;
Toolbar toolbar;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView=inflater.inflate(R.layout.schedule_spinner, container, false);
tabLayout=(TabLayout)rootView.findViewById(R.id.tabs_schedule);
tabLayout.addTab(tabLayout.newTab().setText("Completed"));
tabLayout.addTab(tabLayout.newTab().setText("Upcoming"));
viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
viewPager.setAdapter(new PagerAdapter
(getFragmentManager(), tabLayout.getTabCount()));
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
return rootView;
}
#Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.Score).setVisible(false);
super.onPrepareOptionsMenu(menu);
}
public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
public PagerAdapter(FragmentManager fm, int NumOfTabs) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
ScheduleCompleted tab1 = new ScheduleCompleted();
return tab1;
case 1:
ScheduleUpcoming tab2 = new ScheduleUpcoming();
return tab2;
default:
return null;
}
}
#Override
public int getCount() {
return mNumOfTabs;
}
}
}
Here is my style.xml
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="MyMaterialTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="MyMaterialTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="MyTabLayoutTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse">
<item name="android:textSize">18sp</item>
<item name="android:textAllCaps">true</item>
</style>
</resources>
Here is my v21/Style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
</resources>
In short i used a materialDesign patter in my application.
Below image is implemented inside an activity
Below image is implemented inside into fragment.
In Above image i got the problem.I want like my activity in fragment.
Please help me to solve out this problem.
I guess the above part is coming from the activity, and the below ones from fragment; therefore, if you want that appear to be flat color, without the gradient, then you should remove
android:background="#drawable/gradient"
from the appbar background at both the activity and the fragment layout, although you did not post the activity layout, I guess it has a similar line in it. If the result won't change, then you should change the theme you used; if you cannot, then simply write something like
android:background="#color/color_you_want"

Related Links

Facebook writing dialog don't show message
Convert unicode value to KeyEvent constant in OnKeyboardActionListener.onKey
Tablayout problem with keyboard
how can i know the id of an item in the listview when it has been filtered? Android
android: finding if sd-card is present
Android smoother pinch zoom?
Help/Confused with MediaPlayer for Android?
how to wrap the views inside a HorizontalScrollView?
Ontouch multitouch zooming in Imageswitcher?
Lightweight binary serialization/deserialization frameworks in Android?
How to make the mapView transparent in Android?
Detecting stop event of android media player
Android: querying MediaStore.Audio.Artists.Albums
Android: Image Pixel Question
How to get camera.git or gallery.git from http://android.git.kernel.org/?
Ads only show on android emulator

Categories

HOME
ggplot2
telegram
fpga
amp-html
mjml
socket.io
shiro
spring-data-mongodb
rds
polling
nuget-package
google-admin-sdk
jax-ws
odoo-8
recordrtc
minecraft-forge
project-intu
radgridview
favicon
gource
do-while
production
bourbon
topology
asp.net-core-webapi
ag
kendo-mobile
roundup
has-and-belongs-to-many
mat
apktool
paperjs
twiml
autodesk-designautomation
dumpbin
carriage-return
nested-lists
installscript
slacktextviewcontroller
searchkit
magento-1.9.2.4
google-earth-engine
bc
gdata
metawidget
news
ogc
android-softkeyboard
knime
android-exoplayer
insight
aquamacs
qtranslate
filehandle
swingworker
structuremap4
pocketsphinx-android
gets
cubism.js
meteor-packages
vulcanize
greatest-n-per-group
rspec2
wso2developerstudio
dup
android-dateutils
dbamp
mirror
botan
document-repository
apache-spark-1.3
filesplitting
psr-4
mobility
rcaller
malformedurlexception
maven-scm
bin
c++builder-xe5
code-duplication
facebook-timeline
panda3d
pstack
htdocs
google-floodlight
quotation-marks
inline-formset
delimited-text
easyb
office-2007
dot-emacs
request-headers
wcf-instancing
tui
asynchronous-wcf-call
alsb
firefox-3

Resources

Encrypt Message