I have the following SearchView implementation in the xml, the text entry has been cut from the top as shown in the below image. No matter what textSize I am putting, nothing changes.
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="32dp"
android:gravity="center_vertical"
android:layout_marginTop="10dp">
<SearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="12sp"/>
</LinearLayout>
You can achieve this using a theme:
in styles.xml
<style name="AppSearchView" parent="Widget.AppCompat.SearchView" >
<item name="android:textSize">60sp</item>
</style>
And using a SearchView
<android.support.v7.widget.SearchView
android:id="#+id/searchView"
android:layout_width="350dp"
app:theme="#style/AppSearchView" // use app:theme not in style
android:layout_height="80dp"
android:layout_marginTop="15dp"/>
try this one
you have to pass your SearchView and textSize in this method
private void setSearchviewTextSize(SearchView searchView, int fontSize) {
try {
AutoCompleteTextView autoCompleteTextViewSearch = (AutoCompleteTextView) searchView.findViewById(searchView.getContext().getResources().getIdentifier("app:id/search_src_text", null, null));
if (autoCompleteTextViewSearch != null) {
autoCompleteTextViewSearch.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
} else {
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
autoComplete.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
}
} catch (Exception e) {
LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
autoComplete.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
}
}
update your XML also
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<SearchView
android:id="#+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"/>
</LinearLayout>
sv= (SearchView) findViewById(R.id.search_view);
TextView searchText = (TextView)
sv.findViewById(android.support.v7.appcompat.R.id.search_src_text);
searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
We can directly change in theme.xml
It will affect in whole application, where it has an search view.
Eg,
<item name="colorControlHighlight">#color/colorAccent</item>
<item name="colorControlNormal">#android:color/black</item>
<item name="android:editTextColor">#android:color/white</item>
<item name="android:textColorHint">#android:color/white</item>
<item name="android:textSize">30sp</item>
</style>
Related
Does anyone know how I can change the position of the mentioned part of error floating label (as in the attached image) ? In the picture it is on the left but I want it to be on the right side of the edittext (because of my native language) . I tried gravity and layout gravity but none of them worked out . Thanks in advance .
<android.support.design.widget.TextInputLayout
android:id="#+id/numid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
app:errorEnabled="true"
app:errorTextAppearance="#style/myerror"
android:layout_gravity="center"
app:hintTextAppearance="#style/TextAppearance.AppCompat.TextInputLayout"
style="#style/EditScreenTextInputLayoutStyle">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/tie"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:inputType="number"
android:gravity="right"
android:textAlignment="gravity"
android:hint="#string/hint2"
android:textDirection="rtl"
/>
<style name="TextAppearance.AppCompat.TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#ff0000</item>
<item name="android:layout_gravity">right</item>
<item name="android:textColorHint">#736f6e</item>
<item name="android:gravity">right</item>
<style name="EditScreenTextInputLayoutStyle" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#000</item>
<item name="colorControlActivated">#000</item>
<item name="colorControlHighlight">#ff0000</item>
<item name="colorAccent">#ffff02</item>
<item name="android:textColorHint">#0000ff</item>
</style>
<style name="myerror" parent="TextAppearance.Design.Error">
<item name="android:textColor">#ff0000</item>
<item name="android:background">#000000</item>
<item name="android:gravity">center</item>
</style>
Try this:
Drawable err_indiactor = ContextCompat.getDrawable(this,R.drawable.indicator_input_error);
yourEditText.setCompoundDrawablesWithIntrinsicBounds(null, null, err_indiactor, null);
this is the Drawable indicator_input_error
The code below works for u
public class MainActivity extends Activity {
EditText use, pass;
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
use = (EditText) findViewById(R.id.edituse);
pass = (EditText) findViewById(R.id.editpas);
button = (Button) findViewById(R.id.click);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final String use1 = use.getText().toString();
final String pass1 = pass.getText().toString();
if (!use1.matches("") && !pass1.matches("")) {
Toast.makeText(getApplicationContext(), "Succes",
Toast.LENGTH_SHORT).show();
use.setError(null);
pass.setError(null);
} else if (use1.matches("")) {
use.setError("This field can not be blank");
} else if (pass1.matches("")) {
pass.setError("This field can not be blank");
}
}
});
}
}
And the Xml file
<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="${relativePackage}.${activityClass}" >
<TextView
android:id="#+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="25sp"
android:gravity="center" />
<EditText
android:layout_below="#+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/edituse"/>
<EditText
android:layout_below="#+id/edituse"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editpas"
/>
<Button
android:id="#+id/click"
android:layout_below="#+id/editpas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click"/>
</RelativeLayout>
Hope this helps...and for English this works.For ur language its a right to left writing,then it may be the problem for the left alignment of the error msg.... ...Don't worry try this.
I am using PopupWindow, which is working fine, but the problem is after inflating the layout view that is shown with black border.
final PopupWindow popupWindow = new PopupWindow(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pop_up_window_menu_layout, null);
popupWindow.setContentView(view);
pop_up_window_menu_layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/solid_white"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:text="SAVE"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="#color/black"
android:textSize="#dimen/txt_size_sliding_list" />
I've tried to remove border by using popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)), but problem is still same.
Can anyone tell me how to remove unwanted black border?
I don't see any border around my popup windows, but I do set them up slightly different than you. Hopefully this points you in the right direction.
popup_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#f5f5f5"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/btn_close"
android:text="Close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
activity_main.xml
<?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="match_parent"
android:orientation="vertical"
android:id="#+id/main_view"
tools:context=".MainActivity">
<Button
android:id="#+id/btn_popup"
android:text="Popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/txt_text"
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity implements View.OnClickListener {
View popupView;
Button btnPopup;
Button btnClose;
PopupWindow popupWindow;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
btnClose = (Button) popupView.findViewById(R.id.btn_close);
btnClose.setOnClickListener(this);
popupWindow = new PopupWindow(popupView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
btnPopup = (Button) findViewById(R.id.btn_popup);
btnPopup.setOnClickListener(this);
}
#Override
public void onClick(View v) {
if (v.getId() == R.id.btn_popup) {
popupWindow.showAtLocation(findViewById(R.id.main_view), Gravity.NO_GRAVITY, 100, 200);
//popupWindow.showAsDropDown(btnPopup, 10, 10);
} else if (v.getId() == R.id.btn_close) {
popupWindow.dismiss();
}
}
}
If you getting a black border this means that the default background is set.
this is how you remove it :
popup.setBackgroundDrawable(null);
Try this
Just try this and let me know..
Be sure to create your Pop-up window referencing your custom theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="DialogTheme" parent="android:Theme.Dialog">
<!-- Fill the screen -->
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<!-- No backgrounds and No titles , and no Window Floating -->
<item name="android:windowBackground">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<!-- Set background what you want-->
<item name="android:background">#ff0000</item>
</style>
</resources>
This is because you are sending context inside popup window constructor. -
final PopupWindow popupWindow = new PopupWindow(context);
Change this by popup window view -
View popupView = getLayoutInflater().inflate(R.layout.popup_view, null);
PopupWindow popupWindow = new Pop
Based on this article, I've tried to build a ViewFlipper with multiple RelativeLayouts.
When proceeding as written in article (only change the height), I got (as expected) a ViewFlipper normally displayed :
My xml :
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="fill_parent"
android:layout_height="200dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/img1" />
<TextView
style="#style/ImageTitle"
android:text="Test test" />
</RelativeLayout>
</ViewFlipper>
Style:
<style name="ImageTitle">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:background">#99000000</item>
<item name="android:gravity">center</item>
<item name="android:maxLines">2</item>
<item name="android:textColor">#fff</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">18sp</item>
<item name="android:typeface">sans</item>
</style>
Then I've tried do generate RelativeLayout programmatically with the code below :
public void generateViewForFlipper(String url, int id, String text){
//new RelativeLayout
RelativeLayout relativeLayout = new RelativeLayout(this);
//Params for the RelaviteLayout
final ViewFlipper.LayoutParams frameLayoutLayoutParams = new ViewFlipper.LayoutParams(
ViewFlipper.LayoutParams.MATCH_PARENT,ViewFlipper.LayoutParams.MATCH_PARENT);
//ImageView
ImageView imageView = new ImageView (this);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.img1));
imageView.setScaleType(ScaleType.CENTER_INSIDE);
imageView.setAdjustViewBounds(true);
// Params for the ImageView
final RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT );
//Application title
TextView textView = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);
textView.setText(text);
// Params for application title
final RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 50);
mViewFlipper.addView(relativeLayout, frameLayoutLayoutParams);
relativeLayout.addView(imageView,imageParams);
relativeLayout.addView(textView,textParams);
}
tvtemplate.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/ImageTitle" />
Result screen :
As you can see, text is not aligned to the bottom, not "match_parent", and picture is not cropped..
Thank you
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.myLayout);
...
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.myMenu, menu);
menuBar = menu;
return true;
}
myLayout.xml
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:src="#drawable/myImage" />
</RelativeLayout>
myMenu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menuItem1"
android:icon="#drawable/icon1"
android:showAsAction="always"
android:visible="false"
android:title="#string/menu1">
</item>
<item
android:id="#+id/menuItem2"
android:icon="#drawable/icon2"
android:showAsAction="always"
android:title="#string/menu2">
</item>
</menu>
I have a custom view which I use to place an image in the center of the ActionBar. However, when I put the MenuItems on the ActionBar, the image gets pushed to the left. I don't know how to center the image or fill the RelativeLayout to take the entire ActionBar width. I tried many different things but so far I had no luck. Any help would be appreciated.
When you add your custom view to the ActionBar, you can set custom ActionBar.LayoutParams for your View.
To do what you're trying to do, you could change your code to something like:
mLayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/myImage" />
</LinearLayout>
Called somewhere in onCreate(Bundle b):
public void setUpActionBar(){
View view = getLayoutInflater().inflate(R.layout.mLayout);
ActionBar.LayoutParams lp = new ActionBar.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);
final ActionBar bar = getActionBar();
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
bar.setCustomView(view, lp);
}
I want to implement a collapsible view, exactly like the one from Google Play market. It displays a number of rows from the content, and an arrow, and tapping on the arrow reveals the whole content. Is this implemented with the ExpandableListView or is there any other solution?
Screen shots attached with highlighting what I am looking for.
Thanks.
There is a simpler way:
final TextView descriptionText = (TextView) view.findViewById(R.id.detail_description_content);
final TextView showAll = (TextView) view.findViewById(R.id.detail_read_all);
showAll.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showAll.setVisibility(View.INVISIBLE);
descriptionText.setMaxLines(Integer.MAX_VALUE);
}
});
XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/detail_description_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/detail_description_content"
android:maxLines="5"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/detail_read_all"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
The important part is maxlines and scrollview. This doesn't give a slow animation (that would be a bid more complex) but an instant open effect.
Excuse my horrible english.
Based on Warpzip response
res/values/strings.xml
...
...
<string name="str_more"><![CDATA[<p><b>This is the header</b><u>( see more ..)</u>]]></string>
<string name="str_less"><![CDATA[<p><b>This is the header</b><u>(less ..)</u>]]></string>
<string name="str_details"><![CDATA[<p>A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.A long string of text that do not want to show all the time.</p>]]></string>
...
...
In our layoutIn our layout, we can include a scrollview with a vertical LinearLayout (or with a little work a RelativeLayout). In these:
<TextView
android:id="#+id/txtvw_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/str_more"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtvw_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtvw_tituloEntreTodos"
android:text="#string/str_details"
android:textAppearance="?android:attr/textAppearanceMedium" />
Finally our Activity
view = inflater.inflate(R.layout.f_entretodos, container, false);
info = (TextView) view.findViewById(R.id.txtvw_header);
fullinfo = (TextView) view.findViewById(R.id.txtvw_detail);
info.setText(Html.fromHtml(getString(R.string.str_more)));
fullinfo.setText(Html.fromHtml(getString(R.string.str_detail)));
fullinfo.setVisibility(View.GONE);
info.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (fullinfo.isShown()){
fullinfo.setVisibility(View.GONE);
info.setText(Html.fromHtml(getString(R.string.str_more)));
}else{
fullinfo.setVisibility(View.VISIBLE);
info.setText(Html.fromHtml(getString(R.string.str_less)));
}
}
});
Warpzits's solution upgraded (expand any container content):
A layout XML:
<LinearLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:clickable = "true"
android:focusable = "true"
android:orientation = "vertical"
android:gravity="end">
<ImageButton
android:id = "#+id/expandImageButton"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_margin = "12dp"
android:background = "#00ffffff"
android:src = "#drawable/dropdown_white"
android:onClick="onClickExpandImageButton"/>
<TextInputLayout
android:id = "#+id/container"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:visibility="gone">
<EditText
android:layout_width = "match_parent"
android:layout_height = "wrap_content"/>
</TextInputLayout>
</LinearLayout>
An onClick handler:
public void onClickExpandImageButton(
View expandImageButton) {
expandImageButton
.setRotation(
container.getVisibility() == View.GONE ?
180 :
0);
container.setVisibility(
container.getVisibility() == View.GONE ?
View.VISIBLE :
View.GONE);
}
Image from /res/drawable/:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#f5f5f5"
android:pathData="M7,10 L12,15 L17,10 Z" />
<path
android:pathData="M0,0 L24,0 L24,24 L0,24 Z" />
</vector>