In the above image of skyscanner app, when i click on the search icon then it shows as like below image.
So, how can i overlay the search layout when i click on search icon ?
This may help you and fulfill your requirement. Although its not the perfect solution but it worked for me for setting the view above toolbar.
Use Popup window and inflate the layout of search.
Design the popupwindow location, animationstyle, background etc.. and refer this Using Immersive Full-Screen Mode for systemUiVisibility usage.
PopupWindow mpopup; //declare it globally.
//it will make main background transperent. where mRoot is the root layout.
mRoot.setAlpha(0.50f);
View popUpView = getLayoutInflater().inflate(R.layout.activity_search,
null);
popUpView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
// Creation of popup
mpopup = new PopupWindow(popUpView, RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT, true);
//this will set the transperency of background.and set the background color transperent.
mpopup.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
//set the animation style of popup view.
mpopup.setAnimationStyle(android.R.style.Animation_Dialog);
mpopup.showAtLocation(popUpView, Gravity.NO_GRAVITY, 0, 0);
FloatingActionButton btnSearch = (FloatingActionButton) popUpView.findViewById(R.id.btnsearch);
btnSearch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mpopup.dismiss();
//remove transperency
mRoot.setAlpha(1f);
}
});
activity_search.xml: (Design your layout according to your requirement below is just sample)
<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/coorlay"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/lay_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/textSecondary"
android:orientation="vertical"
android:padding="10dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Write something" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:padding="10dp">
<CheckBox
android:id="#+id/check1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="check1" />
<CheckBox
android:id="#+id/check2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="check2" />
<CheckBox
android:id="#+id/check3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="check3" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/btnsearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/places_ic_search"
android:tint="#color/white"
app:layout_anchor="#id/lay_search"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Now, when you click on search button of ur toolbar then the above view will display. and for background transperency of root layout you can set its alpha on buttonclick and remove alpha on button dismiss. as given in code.
This is the solution i have used
Create a custom layout for action bar and set it this way
ActionBar actionBar = getSupportActionBar();
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.custom_actionbar);
View view = getSupportActionBar().getCustomView();
// find ids using view.
imageButton = (ImageButton)view.findViewById(R.id.action_bar_back);
In that custom layout add all views,which will be there before clicking search and after clicking search
which every view should be visible after search icon is clicked make there visibility as GONE in XML by default,
back, California, search icon visible by default
when user click on search icon make back, California,search icon visibility GONE and make X icon and search hotels visible
You can add search option by using following piece of code and customize it a per your needs.
#Override
public boolean onCreateOptionsMenu(final android.view.Menu menu) {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchView searchView = new SearchView(this);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setQueryHint(getString(R.string.hint_search));
searchView.setIconifiedByDefault(false);
ImageView searchIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
searchIcon.setImageResource(R.drawable.ic_search);
SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchAutoComplete.setHintTextColor(Color.parseColor("#888888"));
searchAutoComplete.setTextColor(ContextCompat.getColor(context, R.color.text));
ImageView searchCloseIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchCloseIcon.setImageResource(R.drawable.ic_clear);
ImageView voiceIcon = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
voiceIcon.setImageResource(R.drawable.ic_keyboard_voice);
voiceIcon.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
menu.getItem(0).collapseActionView();
return false;
}
});
menu.add(getString(R.string.title_search))
.setIcon(R.drawable.ic_search)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
MenuItemCompat.setOnActionExpandListener(menu.getItem(0), new MenuItemCompat.OnActionExpandListener() {
#Override
public boolean onMenuItemActionCollapse(MenuItem item) {
AppGlobal.hideSoftKeyboard(context);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
return true;
}
#Override
public boolean onMenuItemActionExpand(MenuItem item) {
searchView.requestFocus();
AppGlobal.openSoftKeyboard(context);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
return true;
}
});
return true;
}
You can use popup window or create layout inside toolbar like this :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="?attr/colorPrimaryDark"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="40dp">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="California"/>
<TextView
android:id="#+id/subtitle"
android:layout_below="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="California"/>
<Button
android:id="#+id/single_button"
android:layout_below="#+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="California"/>
<LinearLayout
android:id="#+id/ll_button"
android:layout_below="#+id/single_button"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="California"
android:layout_weight="1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="California"
android:layout_weight="1"/>
</LinearLayout>
<TextView
android:id="#+id/tv_spinner"
android:layout_below="#+id/ll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="spinner"/>
</LinearLayout>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp"
android:layout_marginTop="173dp" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Its look like this :
you can show/hide views based on your requirement.
#Dipak please follow the link PersistentSearch this is more than you want,
I use same in my code to really awesome .
Related
I want popup menu like this
that show it after click on button
XML
<item
android:state_pressed="true"
android:id="#+id/fromFirstMonth"
android:title="از ابتدای سال"
android:drawable="#drawable/nav_item_background"/>
<item
android:state_pressed="true"
android:id="#+id/currentMonth"
android:title="این ماه"
android:drawable="#color/blueMenu"/>
<item
xmlns:showAsAction="always"
android:id="#+id/currentSession"
android:title="این فصل"
android:drawable="#color/white"/>
<item
xmlns:showAsAction="always"
android:id="#+id/selection"
android:title="تانتخابی"
android:drawable="#color/blueMenu"/>
</menu>
Java
hourglass.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(Products.this, hourglass);
//Inflating the Popup using xml file
popup.getMenuInflater().inflate(R.menu.hourglass_item, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(Products.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();//showing popup menu
}
});
I want set different background color for each item. i set android:drawable but this does not worked.
I can with this code can change text color but i does not know how can change background color item
Menu menu=popup.getMenu();
MenuItem item = menu.getItem(0);
SpannableString s = new SpannableString("My red MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
If you want to use item tags and do this,as an alternative way you can tryBackgroundColorSpan and write the logic to reformat of the length of your strings.
s.setSpan(new BackgroundColorSpan(Color.RED), 0, s.length(), 0);
out put:
else
If i do that i'll crate a Dialog without a Title
private Dialog fakeDialogUseInstedOfMenuItem;
fakeDialogUseInstedOfMenuItem = new Dialog(MainActivity.this);
fakeDialogUseInstedOfMenuItem.requestWindowFeature(Window.FEATURE_NO_TITLE); // no Title
fakeDialogUseInstedOfMenuItem.setContentView(R.layout.my_custom_view);
and set a fixed or scroll view for that as the requirement
my_custom_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="200dp"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#789"
android:orientation="vertical">
<LinearLayout
android:id="#+id/first_lin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option One"
android:textColor="#000"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FFF"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option Two"
android:textColor="#000"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FFF"></LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
and access items like this,
LinearLayout linearLayoutOneInDialog = (LinearLayout) fakeDialogUseInstedOfMenuItem.findViewById(R.id.first_lin);
out put:
But these things are optional ways
I have a navigation Drawer, the left side is the left navigation drawer, containing TextView "detailsTxt". This contains dynamic text, and I want the navigation drawer to be resized to fit the TextView when the user opens the drawer.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout mlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/app_bg">
<LinearLayout
android:id="#+id/topNavigator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/toolbar_white_space">
<TextView
android:id="#+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:text="Ayman Salah"
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold|italic"
android:layout_marginTop="15dp" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
<!-- drawer layout -->
<LinearLayout
android:layout_width="450dp"
android:id="#+id/leftBar"
android:layout_gravity="start"
android:layout_height="fill_parent"
android:gravity="start|left">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/nbackground">
<TextView
android:id="#+id/detailsTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:text="string/sample_details"
android:textColor="#android:color/widget_edittext_dark" />
</RelativeLayout>
</LinearLayout>
Add listeners for Drawer
Open/Close events
and
Add this code in onDrawerOpen(), found from this answer :
LinearLayout mDrawerListView = (LinearLayout) findViewById(R.id.leftBar);
mDrawerListView.post(new Runnable() {
#Override
public void run() {
DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawerListView.getLayoutParams();
params.width = (int) 100; // for example
mDrawerListView.setLayoutParams(params);
}
});
and set layout_width="0dp" in xml file
Try initializing the Navigation Draw with a zero width, i.e. android:layout_width="0dp", and then execute the snippet below in your onCreate(Bundle savedInstanceState).
// Programatically assigns a custom width to a DrawerLayout.
this.getDrawerLayout().addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
/** Fire-and-forget programmatic width implementation for the DrawerLayout. */
#Override public final void onDrawerSlide(final View pDrawerView, final float pSlideOffset) {
// Recalculate the new LayoutParams.
pDrawerView.setLayoutParams(this.getLayoutParams((DrawerLayout.LayoutParams)pDrawerView.getLayoutParams()));
// Stop listening for future events, once we've configured the size once. (We know the DrawerLayout is the direct parent of the DrawerView.)
((DrawerLayout)pDrawerView.getParent()).removeDrawerListener(this);
}
/** A method used to define the new LayoutParams of the DrawerView. */
private final DrawerLayout.LayoutParams getLayoutParams(final DrawerLayout.LayoutParams pLayoutParams) {
/** TODO: Compute your width here! (i.e pLayoutParams.width = X) **/
// Return the LayoutParams.
return pLayoutParams;
}
});
I use popup menu with custom items.Problems like this
Red lines represents to default width size.
but i want custom smaller width size of items(represents red lines).
public void onClick(View v) {
//Creating the instance of PopupMenu
PopupMenu popup = new PopupMenu(MainLayout.this, mSikBtn);
popup.getMenuInflater().inflate(R.menu.poupup_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return true;
}
});
popup.show();//showing popup menu
}
});
Layout xml file
<ImageView
android:id="#+id/popupBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/selector_sik"
android:layout_weight="1"
android:layout_margin="10dip"
/>
popup_menu.xml file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/one"
android:title="A)."/>
...
<item
android:id="#+id/three"
android:title="E)."/>
</menu>
Similar question: stackoverflow.com
I need to custom popup menu
Just like you, I tried a lot to change the width of the popup menu but was unsuccessful.
Somehow, I found a solution you might be looking for.
First, instead of using popup menu, I used popup window.
Step1: Making a row layout:
<?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="?android:attr/listPreferredItemHeight"
android:background="#android:drawable/list_selector_background"
android:orientation="vertical"
android:padding="3dp">
<TextView
android:id="#+id/ItemA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="15dp"
android:layout_marginTop="3dp"
android:text="A)"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/ItemB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:text="B)"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/ItemC"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:text="C)"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/ItemD"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:text="D)"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText" />
</LinearLayout>
Step 2: Made a method to initialize popup window:
private PopupWindow initiatePopupWindow() {
try {
mInflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = mInflater.inflate(R.layout.row, null);
//If you want to add any listeners to your textviews, these are two //textviews.
final TextView itema = (TextView) layout.findViewById(R.id.ItemA);
final TextView itemb = (TextView) layout.findViewById(R.id.ItemB);
layout.measure(View.MeasureSpec.UNSPECIFIED,
View.MeasureSpec.UNSPECIFIED);
mDropdown = new PopupWindow(layout,FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,true);
Drawable background = getResources().getDrawable(android.R.drawable.editbox_dropdown_dark_frame);
mDropdown.setBackgroundDrawable(background);
mDropdown.showAsDropDown(pop, 5, 5);
} catch (Exception e) {
e.printStackTrace();
}
return mDropdown;
}
Step 3: Simply calling it in the onCreate():
public class MainActivity extends Activity {
ImageButton red, blue;
private PopupWindow mDropdown = null;
LayoutInflater mInflater;
Button pop;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pop = (Button)findViewById(R.id.button1);
pop.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
initiatePopupWindow();
}
});
}
}
Hope this helps you..If it does, accept my answer..:)
Here's the screenshot:
http://imageshack.com/a/img585/7388/dxjo.png
I don't think you can set layout:width in menu, so you might have to create your own view layout. This might help:
Set menu items centered and full-width with ActionBarSherlock
http://developer.android.com/guide/topics/resources/menu-resource.html
Please go through the below image
http://i.imgur.com/3WqhVCj.jpg
I dont have any action bar and I made my custom header using below layouts which is shown in Figure-2
[Linearlayout]
[Relativelayout]
[linearlayout]
Back Button
App Icon
My APP text
Overflow Icon
[/Linearlayout]
[/Relativelayout]
[/linearlayout ]
now i need the dropdown like shown in Figure-1 on clicking overflow icon which is shown in red box on top right in Figure-2
how could i do this? I have tried spinner it giving me popup but i need just dropdown shown in Figure-1.
plz suggest me
First of all create a function or method in your java class file:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater menuINF= getMenuInflater();
menuINF.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.***:
break;
}
And add menu content by adding menu folder in res folder and create menu.xml in that folder (res->menu->menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_add" android:title="Add" android:icon="#drawable/icon"/>
<item android:id="#+id/menu_DashBoard" android:title="DashBoard" />
<item android:id="#+id/menu_Master_Entry" android:title="Master Entry" />
<item android:id="#+id/menu_Product_Section" android:title="Product Section" />
<item android:id="#+id/menu_Retailers_Orders" android:title="Retailers Orders" />
</menu>
This may help you Its works for me.
Use dialog (Example)
And to place dialog to correct height and width use
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.CENTER_RIGHT;
BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.urdrawable);//urdrawable is your top bar image
int height=bd.getBitmap().getHeight();
//int width=bd.getBitmap().getWidth();
//wmlp.x = width; //x position
wmlp.y = height; //y position
Try this..
For list_popup.xml
<?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="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#44444d"
>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text1"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text2"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text3"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
</LinearLayout>
java
LayoutInflater layoutInflater= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.list_popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,200,LayoutParams.WRAP_CONTENT);
onClick.
show_options.setOnClickListener(new Button.OnClickListener(){
public void onClick(View arg0) {
if(popupWindow.isShowing())
popupWindow.dismiss();
else
popupWindow.showAsDropDown(show_options, 50, 0);
}
});
show_options is your overflow icon image name
Here is some example
http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html
http://www.androidhub4you.com/2012/07/how-to-create-popup-window-in-android.html
Is there any similar theme generator as HoloColors or Action Bar Style Generator which would help us change theme of Dialogs and AlertDialogs in our apps?
My app uses Holo theme and I managed to change style of views such as EditTexts and Buttons but they remain unchanged when they appear in a Dialog. I would also like to change color of the blue line under a title.
I've found a few question and answers related to this topic but they practically say it's not even possible. I cannot believe it isn't.
At least for the AlertDialog it is possible. here i posted my solution of a function which is called at some point (for example button click) in your code and creates an alert dialog own layout over your screen.. the layout is a normal layout.xml which you can define the way you want. works perfect for me!
private void showAddUserGeneratedStationDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
AmplifyActivity.this);
LayoutInflater inflater = getLayoutInflater();
//inflate your layout.xml
alertDialog
.setView(inflater.inflate(R.layout.dialog_add_station, null));
//show dialog over activity screen
final AlertDialog ad = alertDialog.show();
//put actions to your ui-elements
Button cancelBtn = (Button) ad
.findViewById(R.id.list_user_generated_cancelBU);
cancelBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ad.cancel();
}
});
Button doneBtn = (Button) ad
.findViewById(R.id.list_user_generated_doneBU);
doneBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//get sth from your layout f.e. some textInput
String stationUrl = ((TextView) ad
.findViewById(R.id.list_user_generated_stationURLInput))
.getText().toString();
// did some other things
ad.dismiss();
}
});
}
and my layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list_user_generated_addStationDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99000000"
android:clickable="true"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="300dp"
android:layout_height="200dp"
android:padding="10dp"
android:background="#000"
android:orientation="vertical" >
<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="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/list_user_generated_cancelBU"
style="#style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:text="#string/cancel" />
<TextView
style="#style/AmplifyHeadlineElement"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="#string/list_userGenerated_addStation" />
<Button
android:id="#+id/list_user_generated_doneBU"
style="#style/ButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:text="#string/done" />
</LinearLayout>
<EditText
android:id="#+id/list_user_generated_stationURLInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:background="#FFF"
android:ems="10"
android:hint="#string/list_userGenerated_addUrlExample"
android:inputType="textNoSuggestions" >
</EditText>
<!-- MORE BUT I DELETED IT FOR BETTER OVERVIEW -->
</LinearLayout>
</LinearLayout>