I decided to add selected option in my TextView, but when it was selected and addition menu pop up - it cut TextView down below.
Before selection:
Before selection:
https://i.stack.imgur.com/9jbMN.png
After selection:
https://i.stack.imgur.com/C3XWh.png
How can I fix it?
activity_main:
<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:background="#color/light_yellow"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/selected_date_field"
style="#style/MainTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="#string/selected_date_field" />
<TextView
android:id="#+id/selected_date"
style="#style/SecondTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/selected_date" />
<TextView
android:id="#+id/in_minutes_field"
style="#style/MainTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textIsSelectable="true"
android:textColorHighlight="#color/blue"
android:text="#string/in_minutes_field" />
<TextView
android:id="#+id/in_minutes_till_date"
style="#style/SecondTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/in_minutes_till_date" />
</LinearLayout>```
you can try app:autoSizeTextType:uniform for that textView.
Note: If you gave already size like "textsize: 15sp" remove that line.
Found out that the problem was due to the fact that in the themes.xml I had the same color in <item name="colorOnPrimary">#color/blue</item> (background) and <item name="colorSecondary">#color/blue</item> (color of handlers), because of it I couldn't see handlers
Thanks everyone!
Related
I am trying to place two image buttons and some text on a single line. Here is the XML for the layout:
<?xml version="1.0" encoding="utf-8"?>
<mycompany xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="28dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_alignParentLeft="true"
android:src="#drawable/button_delete" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/sectionAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/button_add" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
</mycompany>
The selector XML for each of the buttons in drawable:
button_delete.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/delete_button_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/delete_button"
android:state_focused="true" />
<item android:drawable="#drawable/delete_button" />
</selector>
button_add.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/button_add_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/button_add_normal"
android:state_focused="true" />
<item android:drawable="#drawable/button_add_normal" />
</selector>
In the builder all looks well:
But in the application the gray background is lost and the edges of the image (which are transparent) are shown, but only for the first image:
Strangely, the first image button is not recognizing the transparent background of the image. Additionally I needed to mess with the width and height of the RelativeLayout and the first ImageButton to even get it close to the right size. With the 2nd I did not have to do anything. There is nothing special with the first image.
Here are the images from the directory:
One last issue - How do you make the text wrap before the 2nd image if it is too long for the space? Right now it writes under the 2nd image before wrapping:
Here are all the delete images. Seem to have transparent backgrounds, but I am far from a Gimp expert. Also not sure if StackOverflow keeps the original..
Update
I have verified the images are transparent. The image still has the white background. I have also updated the XML to look like this:
<?xml version="1.0" encoding="utf-8"?>
<mycompany xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/button_delete" />
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:layout_toEndOf="#+id/sectionDelete"
android:layout_toLeftOf="#+id/sectionAdd"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/sectionAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/button_add" />
</RelativeLayout>
<View
android:id="#+id/line"
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
</LinearLayout>
</mycompany>
You should use:
<ImageButton
android:id="#+id/sectionDelete"
android:layout_width="35dp"
android:layout_height="28dp"
android:layout_alignParentLeft="true"
android:src="#drawable/button_delete"
android:background="#android:color/transparent"/>
Use "#null" like background on ImageButton:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/bkash"
android:id="#+id/bid1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#null" />
You haven't included the actual PNG file you are using as an icon for your delete button (screenshot from Windows's Explorer showing this file on your disk isn't quite enough), but I am almost sure that this file lacks an alpha channel. Instead, there is a white color on every pixel you'd like to be set with zero alpha channel value.
Opening your graphic in some image editor and changing these white pixels to transparent will solve your problem, but as for the reason why your layout "looks different" in builder than on your device, it's because there is a default theme applied by the system to every app, you can read more about it here: https://developer.android.com/guide/topics/ui/look-and-feel/themes.html
This default, OS and device specific set of values determines things that aren't determined by app's authors.
In the case of your device, its OS determined app's background color to be gray, which wasn't the case with your builder. Your builder chose the background to be white. Your delete button's graphic never was transparent, but on the white background of your builder it looked like it was.
To make it look like on builder, you need to specifically apply the background by yourself to the root of your view. In this case, it's a LinearLayout which should look like this:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
1) #DimDim had the right solution, if it didn't work, the delete button may have white background in the image, cross check with a png viewer.
2) To prevent overflow of text, try this
<TextView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/sectionDelete"
android:layout_toLeftOf="#+id/sectionAdd"
android:text="test"
android:textAllCaps="true"
android:textColor="#color/navigation_bar"
android:textSize="16sp"
android:textStyle="bold" />
And put the sectionAdd Image button above this textview in the XML as this textview needs reference to the sectionAdd.
I was needed to create a custom title view to be able show message and title, when the list appears. Because the list appears in the dialog's content area. So the dialog cannot show both a message and a list.
My custom view is a LinearLayout :
<?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:padding="24dp"
android:paddingBottom="20dp"
style="#style/Base.Theme.AppCompat.Dialog.Alert"
>
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/alert_dialog_custom_message_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"/>
</LinearLayout>
Padding values and text size was given in accordance with the information given material design guidelines
However, This appearance is different from the default one.
my question:
How can I create a textView that has a same style with default one ?
Maybe there is a way like setting a style to my TextView
Edit : I just want to set style attribute that makes its visuality same as default AlertDialog.
My textview is already like this:
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
I want to do that just like this :
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
style="?android:attr/titleTextStyle"
/>
In your style you can use this
<style name="TextAppearance.AlertDialogPro" parent="android:TextAppearance" />
for you textview you can add style
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
style="#style/TextAppearance.AlertDialogPro"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
I am making an application using Google maps. I am using AutoCompleteTextView to get suggestions of places. The output is as follows :
As you can see from the image, the border of the suggestion box is overlapping the TextView. I am using custom item layout with a Textview inside a Linear Layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:orientation="horizontal" >
<TextView
android:id="#+id/resultValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:textColor="#474040"
android:textSize="15sp" />
</LinearLayout>
Is there a way to bring the suggestion window down and to remove or change the colour of the grayish border of the suggestion window ?
Was doing the same thing as in the accepted answer, but was still having the overlap issue. To fix that make this call:
autocompleteView.setDropDownVerticalOffset(0);
Try like this, android:popupBackground="#EFEEEC"// change according your border you want for the suggestion box
<AutoCompleteTextView
android:id="#+id/autocomplete"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/text_area"
android:inputType="text|textNoSuggestions|textMultiLine"
android:paddingLeft="10dp"
android:popupBackground="#EFEEEC"
android:textColor="#333333"
android:textColorHint="#9c9c9c"
android:textSize="18sp"
android:completionThreshold="1" />
and auto_textview.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:textColor="#333333"
android:layout_margin="15dp"
android:textSize="16sp" >
</TextView>
text_area9.png
Final output will look like
Hope this help you.
Use a custom drawable like
AutoCompleteTextView txtNames= (AutoCompleteTextView)findViewById(R.id.editBox);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.drawable.customlist, restList);
txtRestNames.setAdapter(adapter);
and add customlist as
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cust_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:textSize="12dp"
android:singleLine="false"/>
Change the parameters/color to suit your needs. Try it....hope it helps
I would like to align two buttons on the bottom of a relative layout that is wrapped inside of a linear layout.
I am unable to get the view favorites button to be on top of the search button. There is a big space as you can see in this image:
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="#string/SearchRestaurantsCity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCity" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchCity" />
<TextView
android:text="#string/SearchRestaurantsState"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchState" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/etRestaurantSearchState" />
<TextView
android:text="#string/SearchRestaurantsCategories"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tvRestaurantSearchCategories" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/spRestaurantSearchCategories" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<Button
android:text="#string/btnViewFavoriteRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnViewFavoriteRestaurants"
style="#style/ButtonText"
android:padding="5dp"
android:layout_below="btnSearchRestaurants" />
<Button
android:text="#string/btnSearchRestaurants"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/btnSearchRestaurants"
style="#style/ButtonText"
android:layout_alignParentBottom="true"
android:padding="5dp" />
</RelativeLayout>
There are 2 things wrong with the XML.
For starters, you can't refer to the button btnSearchRestaurants before it's defined.
Secondly, you've defined btnSearchRestaurants to align-parent-bottom, and then tried to define that btnViewFavoriteRestaurants would be below that button. It should be above it (as per your description).
If you're trying to put the first button I can see inside RelativeLayout, I'd try to change the following line:
android:layout_below="btnSearchRestaurants" />
for this one:
android:layout_above="#+id/btnSearchRestaurants" />
Part of the space is reserved for all the elements of the layout I can see inside the LinearLayout,and the + is because the button btnSearchRestaurants is below so it is not created yet
I think the problem is at
android:layout_below="btnSearchRestaurants"
It should be
android:layout_below="#id/btnSearchRestaurants"
In your xml code I think you should correct this line
android:layout_below="btnSearchRestaurants"
as you want it to be above the Search Restaurants button it should be
android:layout_above="#id/btnSearchRestaurants"
I changed below to above for obvious reasons (you want it above the other button not below it) and added #id/ because you will be searching for the button id.
In main activity of my application I need a control which should look like ListPreference in PreferencesActivity. I mean, 2 lines: title and current value and down arrow icon on the right.
I've tried to use TwoLineListItem for this:
<TwoLineListItem android:id="#+id/twoLineListItem1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:onClick="onButtonClick" android:focusable="true"
android:background="#android:drawable/list_selector_background">
<TextView android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content" android:id="#android:id/text1"
android:text="Upload into:" />
<TextView android:layout_below="#android:id/text1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_alignLeft="#android:id/text1" android:layout_height="wrap_content"
android:id="#android:id/text2" android:text="<not set>"
android:layout_width="wrap_content" />
<!-- <ImageView android:layout_width="wrap_content" android:layout_alignParentRight="true"
android:id="#android:id/selectedIcon"
android:src="???"> </ImageView> -->
</TwoLineListItem>
It all works except of arrow icon: I can't find proper resource which system uses for it.
How this could be solved?
Or maybe I should use another control instead of TwoLineListItem?
Or maybe even try to implement my activity as PreferencesActivity (thought I need some EditText controls in my activity)?
For the reference, what I need is on the left picture:
http://androinica-serve.s3.amazonaws.com/wp-content/uploads/2010/11/evernote_comp2.png
wow, this question is so old and i can't believe no one answered it correctly lol. the layout you were looking for is in the sdk tree under:
[android-sdk-root]/platforms/[your-platform]/data/res/layout/preference.xml
you'll find this and any other sdk defined layouts in this folder. fish around in the res folder and see what's available. sorry it's a year late, but there ya go.
Use this layout and modify according to your need...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentLeft="true">
<TextView android:layout_width="fill_parent"
android:text="ggggggggg"
android:layout_height="wrap_content" android:id="#android:id/text1"
/>
<TextView android:layout_below="#android:id/text1"
android:text="ssssssssssss"
android:layout_height="wrap_content"
android:id="#android:id/text2"
android:layout_width="wrap_content" />
</LinearLayout>
<ImageView android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:id="#android:id/selectedIcon"
android:layout_height="wrap_content"
android:src="#drawable/icon"
/>
</RelativeLayout>
You might try using #android:drawable/btn_dropdown to get the system resource and setting that as the background.