How to make a dropdown in Tablayout in android? - android

I have an app in which I have a tab layout which contains three tabs with a different fragment.What I want to add a dropdown to tab 0. How do I do that
code:-
mTabLayout.getTabAt(0).setIcon(tabIcons[0]);
mTabLayout.getTabAt(1).setIcon(tabIcons[1]);
mTabLayout.getTabAt(2).setIcon(tabIcons[2]);
enter image description here

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatSpinner
android:layout_width="wrap_content"
android:id="#+id/spinner"
android:layout_height="wrap_content"/>
</LinearLayout>
//Java code
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.test,
(ViewGroup) findViewById(R.id.spinner));
mTabLayout.getTabAt(0).setView(layout);

Related

Set a title for inflated view activity

My activity screenshot having red highlight area where i want to set title
I inflated a view in my activity.I want to set a title for it, setTitle and label tag in manifest is not working i have tried like thousand times.
How to set title in highlighted area of screenshot my code for this is below
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameHome);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View inflate = layoutInflater.inflate(R.layout.activity_main, null, true);
frameLayout.addView(inflate);
If you want to set a title at the right corner of your app bar, you can put a TextView in the Toolbar.
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Your Title"
android:layout_gravity="end"/>
</FrameLayout>
</android.support.v7.widget.Toolbar>
Add this Toolbar in your Activity layout at the top: activity_main.xml

Android How to Create Custom ActionBar with custom up button and custom background image

I'm a beginner with Android. I want to create a custom actionbar for my app, with a custom background image and a custom up button, I have tried but result is not exactly like what I want.
My custom action bar I want my custom background fit to screen. How can I do?
This is my custombar_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:background="#drawable/bar">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:scaleType="fitStart"/>
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginLeft="?attr/actionBarSize"
android:layout_marginRight="?attr/actionBarSize"
android:text="SFlashCard"/>
</LinearLayout>
And in Main activity:
ActionBar actBar = getSupportActionBar();
actBar.setDisplayShowHomeEnabled(false);
actBar.setDisplayShowTitleEnabled(false);
LayoutInflater inflater = LayoutInflater.from(this);
View customView = inflater.inflate(R.layout.custom_actionbar, null);
actBar.setCustomView(customView);
actBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actBar.setDisplayShowCustomEnabled(true);
Many thanks for all support!

Dynamic content inside scrollview lost last view

I have ScrollView with LinearLayout and button inside:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/layout_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layout_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/card_color"
android:orientation="vertical"
android:padding="10dp">
</LinearLayout>
<Button
android:id="#+id/button_leave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/leave" />
</LinearLayout>
</ScrollView>
Then in code I add view to layout_list:
View view = LayoutInflater.from(this)
.inflate(R.layout.item_member, mLayoutMemberList, true);
If I add not many items, then button_leave is visible. But if I add a lot of items (more then showing on the screen) then button is not visible on the screen even if I scroll down.
Update:
Looks like it is bug of android.support.design.widget.CoordinatorLayout. I change it to simple linear layout and all work good.
Try like this:
I think layout view is working fine and try below code,
LayoutInflater inflater = context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.layout_list, null, true);

ListView and Button(android)

I want to make to the listView with an increase fell button:
My attempt at implementing this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#214075"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listbascet"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
<Button
android:id="#+id/sendtoEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Заказать услуги" />
</LinearLayout>
You would better remove the button from the XML and add it to another one.
Then you can use the inflate to get the button and add it as footer view to the original list view.
This way it will be at the end of the list and scroll will it as well!
How to inflate:
LayoutInflater inflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.mylayout, null);
Button item = (Button) view.findViewById(R.id.item); // how to reference your button
How to add footer:
listView.addFooterView(view); // view is the inflated layout.
More details about footer view contained in this answer as well.

Elements inside RelativeLayout not showing up

I am trying to design a 3D page curl.
In my mainActivity, I have a viewPager which contains pages to be curled. For each page I have a separate layout file.
In the layout file if i just add a text view like below it is showing up fine:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/PageTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/green"
android:text="VIEW 1" /> -->
But if I wrap the textview inside relative layout, it just shows a white blank screen and textview is not shown.
<RelativeLayout 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=".DemoActivity" >
<TextView
style="#style/PageTitle"
android:id="#+id/sampletextview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="VIEW 1" />
</RelativeLayout>
Can someone please help me to know why i am not able to use relative layout in my view layout file:
I inflate the view like this:
LayoutInflater inflater = (LayoutInflater) myAppContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view1 = inflater.inflate(mViewIds[0], null);
Try changing the second parameter of the inflate() call from null to the ViewGroup that view1 is added to. Or post the code where you add it (and include the part where you define the LayoutParams).

Categories

Resources