Hide Tablayout in some Fragments - android

I would like to hide my Tablayout in some Fragments my app will show up. One solution would be setting the android:aylout_height attribute of the TabLayout to eiher "0dp" or "wrap_content". But how do I set the height to 0dp programmatically? Is that even possible with a TabLayout?

In the fragments that you want your TabLayout to not show...
tabLayout.setVisibility(View.GONE);
I would put the above part of your code in your fragment's onCreateView() method.
Then, in fragments where you want it to show again:
tabLayout.setVisibility(View.VISIBLE);

xml:
android:visibility="gone"
code:
TableLayout layout= (TableLayout ) view.findViewById(R.id.layout_table);// change id here
layout.setVisibility(View.GONE); //VIEW.VISIBLE etc.

Related

Create margin on Fragment with Widget

This is an example of my activity with element fixed and automatic margin:
But when use fragment:
Its possibile to set margin on fragment?
In the fragment container in your activity xml, set padding to the container. In your specific case, set it to the ViewPager.
example:
android:padding="10dp"
Try providing margin to the container you are using to contain your fragment.
for eg. if you are using the framelayout as a container give margin to the frame layout.

How to set custom layout into material toolbar?

I'm trying to make toolbar like in this app:
play.google.com/store/apps/details?id=com.pickup.pickrup
But I can't set custom layout into toolbar.
After adding custom layout appears some margins below and above.
Help me please!
The Toolbar is just a ViewGroup, so if you have your layout or custom view you can just add it to the Toolbar using the ViewGroup#addView(View view) method. For example, if you instantiated your view and called it myView, you can do: myToolbar.addView(myView)
I have solved this problem specifying instead layout height android:layout_height="wrap_content"
this - landroid:layout_height="?actionBarSize", which is 56dp.
So margins from top and bottom have dissapeared.

How to change Android ViewPager Background Color?

ViewPager Background is grey. I can't find on internet any clear article that shows how to just change that background color in black for example.Any idea will be appreciated.
You can achieve it in 2 ways,
1.Add the following in your ViewPager in the xml
android:background="#000000"
2.Do it dynamically like below,
ViewPager pager= (ViewPager)findViewById(R.id.pager);
pager.setBackgroundColor(Color.BLACK);
Try this
private ViewPager mPager;
mPager = (ViewPager) view.findViewById(R.id.pager);
mPager.setBackgroundColor(Color.BLACK);
A ViewPager is not grey by default, it's transparent like other ViewGroups, so you will see your parent layout background or window background by default.
If you want to change the background color of your whole Activity, I suggest that you override the android:windowBackground attribute in your Activity's theme, which is more efficient.
You can set android:background="#android:color/transparent" to ViewPager in your xml file
and set android:background="#android:color/black" for parent layout.
I hope this will help.

Viewpager and containers width

in a fragment I have a ViewPager that instantiate views (viewpager is the top left white box, the view is the blue box with "AAAAA" inside, padded by 20dp):
The viewpager is "match_parent" inside his fragment. How to "shorten" the width of the containers of the viewpager to achieve a layout like this?
Done! setPageMargin with a negative value & padding inside the view! :)

How to hide framelayout dynamically in android

I want to hide framelayout dynmically in android, How I can achieve this.
provide an id attribute to your frameLayout by defining it in xml file as:
android:id="#+id/someID"
and in code, write following:
FrameLayout layout = (FrameLayout)findViewById(R.id.someID);
layout.setVisibility(View.GONE);
You can also use
View.INVISIBLE
which means the element will be still there.
Change the visibility like this:
FrameLayout layout = (FrameLayout) findViewById (R.id.your_id);
layout.setVisibility (View.GONE); // or View.INVISIBLE, depending on what you exactly want
You can hide or show views using setVisibility(int).

Categories

Resources