I have a TextView with some text that has URL's. I have used Linkify to turn them into clickable URL's:
Linkify.addLinks(bodyTextView, Linkify.WEB_URLS);
However, when I click on text that is NOT a URL the text color changes. This also happens with the textview is set to AutoLink.
Here is my layout:
<?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">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/headerLinearLay"
android:orientation="horizontal" android:padding="4px">
<ImageView
android:id="#+id/avatarImageView"
android:layout_height="48px" android:layout_width="48px"></ImageView>
<TextView
android:id="#+id/usernameTextView"
android:text="TextView"
android:paddingLeft="4dp"
android:layout_toRightOf="#id/avatarImageView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></TextView>
</RelativeLayout>
<TextView android:text="TextView" android:layout_height="wrap_content" android:id="#+id/bodyTextView" android:textSize="24sp" android:layout_width="fill_parent" android:autoLink="web"></TextView>
<TextView android:text="TextView" android:layout_height="wrap_content" android:id="#+id/dateTextView" android:layout_width="fill_parent" android:layout_weight="1"></TextView>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/toolbarLinearLayout" android:background="#color/solid_yellow" android:padding="5dip">
<Button android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:id="#+id/replyButton" android:text="Reply"></Button>
<Button android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="RT" android:id="#+id/rtButton"></Button>
<Button android:id="#+id/dmButton" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="DM"></Button>
</LinearLayout>
</LinearLayout>
Adding:
android:textColor="#ffffff"
to TextView element in xml solves problem... it seems that overriding textcolor overrides other color styles related to element... see this question: Android text view color doesn't change when disabled
That is the default behaviour. You can set the text colour explicitly using the android:textColor attribute, but then you do not see any visual change to the link when it is clicked. One solution is to set android:textHighlightColor to match the normal text colour. The non-link text stays the same, and you see a visual cue when the link is clicked (the background of the link turns the colour of the rest of the text).
Related
I have following problem, I want to add a ImageView (the Google Play button) to my dialog which stays in place, no matter which device the app is running on.
Here is what it should look like:
This is what it looks like on some devices:
Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/goProDialogImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/goldversiondialog"/>
<ImageView
android:id="#+id/googleplaybutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/goProDialogImage"
android:layout_alignBottom="#+id/goProDialogImage"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:maxHeight="250dp"
android:maxWidth="250dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:src="#drawable/gpbutton" />
</RelativeLayout>
How can I tell the app to never put the Image above the golden veil?
Do this:
<LinearLayout
android:weightSum="1"
android:gravity="end"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/googleplaybutton"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_logo" />
</LinearLayout>
I have removed some of your properties, the key point is that you need to use weightSum in LinearLayout and apply weight to your ImageView(I have given 0.5, you can change according to your need). Also, do not set android:scaleType to fitXY, keep the aspect ratio so the height will change according to the width.
I want to separate the 4 icon with equal space like pic1.
And the XML code for pic1 is:
However, at the first time, I set the Blank View height as wrap_content, then the result showed like this:
.
The code for pic2 is:
.
The only difference is highlight by red rectangle.
In the case of this layout, you will get more from a ConstraintLayout.
Specifically, setting your icons within a ConstraintLayout would look like this to get the balanced look you're going for:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/image_2"
app:layout_constraintHorizontal_chainStyle="spread_inside"/>
<ImageView
android:id="#+id/image_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check"
app:layout_constraintStart_toEndOf="#id/image_1"
app:layout_constraintEnd_toStartOf="#id/image_3"
app:layout_constraintHorizontal_chainStyle="spread_inside" />
<ImageView
android:id="#+id/image_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check"
app:layout_constraintStart_toEndOf="#id/image_2"
app:layout_constraintEnd_toStartOf="#id/image_4"
app:layout_constraintHorizontal_chainStyle="spread_inside" />
<ImageView
android:id="#+id/image_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/check"
app:layout_constraintStart_toEndOf="#id/image_3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_chainStyle="spread_inside"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The takeaways from this snippet that get your look are:
horizontal Orientation for the ConstraintLayout
Constraints for each ImageView that attach them to the one before and after
First view is constraint to the parent, specially, as is the last view
app:layout_constraintHorizontal_chainStyle="spread_inside", says to spread them out evenly within the available space.
If you don't want them touching the sides, add padding to the left/right of the parent ConstraintLayout.
Use this code in place of that linearlayout containing all the icons:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<!--keep your first icon code here-->
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<!--keep your second icon code here-->
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<!--keep your third icon code here-->
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<!--keep your fourth icon code here-->
</LinearLayout>
</LinearLayout>
My understanding was that the wrap_content take as much space as needed by its contents. But doesn’t this apply to TextViews as well?
In the following layout why when I change the font of TextView with id real_status to 24 the text is partially hidden? I was expecting that due to the wrap content the enclosing TextView it would wrap around the 24 sp and display the text fine. It is fine with 18sp.
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:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/real_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/full_display_name"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/full_display_name"
android:gravity="center_vertical"
android:textSize="24sp"
android:textStyle="bold"
tools:text="Active"
/>
<TextView
android:id="#+id/full_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#id/real_status"
android:gravity="center_vertical"
android:text="The real user status:"
android:textSize="16sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/full_display_name"
android:gravity="right"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone"
tools:text="Just a text view"
tools:visibility="visible" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
With 18sp:
With 24sp:
UPDATE:
Following the answers I removed the layout top/bottom and the font adjusted but now I see that the TextView overlaps with the next widget. Adding red background is more visible.
I thought that by “growning” the TextView the rest would move down and not overlap
whenever You suffering from this type of problem You can LiniarLayout is best if You understand it very well. because of wrap_content and match_parent is simple to handle in LiniarLayout.
lets understand it.(For Your case)..
1.take two LiniarLayout(parent have verticle orientation..)
i give Id LL1(horizontal) and id LL2 for your case
2.in first layout two textview #+id/full_display_name and #+id/real_status
in real_status have match_parent in width so it easy to divide parent(fill_parent) and set its android:gravity="right"
3.LiniarLayout as it is without relate
See belove XML code...
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/LL1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/full_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The real user status:"
android:textSize="16sp" />
<TextView
android:id="#+id/real_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Active"
android:textSize="26sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/LL2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/real_status"
android:gravity="right" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Just a text view" />
</LinearLayout>
</LinearLayout>
It will help you Your GUI give bestView in All devices with any size of text
Hope it help You
Remove these two line will fix your problem
android:layout_alignBottom="#+id/full_display_name"
android:layout_alignTop="#+id/full_display_name"
Yes the wrap_content will take as much space needed by the view. It will also applied to the TextView also. The problem here is you written android:layout_alignBottom="#+id/full_display_name" to real_status text view. This attribute is overriding the wrap_content So remove allignBottom attribute from the text view.
UPDATE
For your bottom linear layout update the line
android:layout_below="#+id/full_display_name"
with
android:layout_below="#+id/real_status"
Does anyone know if there is a possible way to design the android buttons like this:
I'd say these are regular buttons with transparent background and icons set through drawableTop attribute. So an xml for such a button would look like:
<Button android:drawableTop="#drawable/icon" android:background="#android:color/transparent"/>
Try this
<Button android:drawableTop="#drawable/icon" android:background="#android:color/transparent"/>
ALso you can design this type of bottom bar using Tab in android
Click here
Also you can design this type of button using radio button
Click here
For that i think need to create the custom view for tab and call in tabhost
http://joshclemm.com/blog/?p=136
Thank you
okay
--take one layout and aligng it ALIGNPARENTBOTTOM = TRUE
now set background of that Layout to THIS BLACK
-- now take five button in that Layout Horizontal
now take images like these Transparent and set it to the buttons
-- also get Images for HOVER action
and set it on click of that particular button
(use layout_weight for setting equall sizes of button)
Have Fun!!
I have done same thing in one of my app. Here I am giving the xml code for this
<?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="60dp"
android:background="#000"
android:gravity="center_vertical">
<LinearLayout
android:layout_width="60dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/reviewLayout"
android:gravity="center_horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/reviews"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Review"
android:textColor="#FFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="60dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/nearbyLayout"
android:layout_toRightOf="#id/reviewLayout"
android:gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/nearby"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nearby"
android:textColor="#FFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="60dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/searchLayout"
android:layout_toRightOf="#id/nearbyLayout"
android:gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/search"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:textColor="#FFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="75dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/bookmarkLayout"
android:layout_toRightOf="#id/searchLayout"
android:gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/bookmarks"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bookmarks"
android:textColor="#FFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="60dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/settingsLayout"
android:layout_toRightOf="#id/bookmarkLayout"
android:gravity="center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:src="#drawable/settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:textColor="#FFF"/>
</LinearLayout>
</RelativeLayout>
Use this layout where you want using include tag, and call it in your Activity.
Here I am giving the code to include this in Activity.
private LinearLayout reviewLay,nearbyLay, searchLay, bookmarkLay, settingLay;
reviewLay = (LinearLayout)findViewById(R.id.reviewLayout);
nearbyLay = (LinearLayout)findViewById(R.id.nearbyLayout);
searchLay = (LinearLayout)findViewById(R.id.searchLayout);
bookmarkLay = (LinearLayout)findViewById(R.id.bookmarkLayout);
settingLay = (LinearLayout)findViewById(R.id.settingsLayout);
reviewLay.setOnClickListener(this);
nearbyLay.setOnClickListener(this);
searchLay.setOnClickListener(this);
bookmarkLay.setOnClickListener(this);
settingLay.setOnClickListener(this);
btEdit.setOnClickListener(this);
Here I have used a layout instead of button and I am setting onclicklistener for each layout. Now override onclick method and do what you want with each layout
I have a simple LinearLayout with one TextView and one ImageView. I want the text in the TextView to be aligned to the right, but the result show that the Text was aligned to the left. Is there anything wrong with my layout xml? Thanks.
<?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="wrap_content" android:background="#E8E3E4">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
>
<TextView android:layout_width="260dp" android:layout_height="wrap_content"
android:text="More Comments" android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp"
android:layout_height="wrap_content" android:src="#drawable/arrow_right"
android:layout_gravity="center" android:scaleType="centerInside" />
</LinearLayout>
</LinearLayout>
Thanks, Michael. But the workaround you mentioned doesn't work either.
I tried to use RelativeLayout, but it still gave me result like:
More Comments (Icon)
What I expected is
More Comments (Icon)
The RelativeLayout xml is below. Is there anything wrong with it?
<?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">
<TextView android:id="#+id/label" android:layout_width="260dp"
android:layout_height="wrap_content" android:text="More Comments"
android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:layout_gravity="right" />
<ImageView android:layout_width="50dp" android:layout_height="wrap_content"
android:src="#drawable/arrow_right" android:layout_gravity="center"
android:scaleType="centerInside" android:layout_toRightOf="#id/label" />
</RelativeLayout>
Following the workaround in Michael's comment, I have the XML below. I expected the output to be:
RightLeft
but the actual output is:
Right Left
So the workaround doesn't work for me. Any thoughts?
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1.0"
android:text="RIGHT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="LEFT"/>
</LinearLayout>
LinearLayouts with a horizontal orientation don't support right/left gravity. You can find a workaround here.
I figured out what is wrong with my xml. I should have used gravity instead of layout_gravity to right-align the text in TextView. The following XML works as expected.
<?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">
<TextView android:id="#+id/label" android:layout_width="260dp"
android:layout_height="wrap_content" android:text="More Comments"
android:textStyle="bold" android:background="#ff0000"
android:textColor="#121222" android:gravity="right" />
<ImageView android:layout_width="50dp" android:layout_height="wrap_content"
android:src="#drawable/arrow_right" android:layout_gravity="center"
android:scaleType="centerInside" android:layout_toRightOf="#id/label" />
</RelativeLayout>
I've done only a few projects with android, but android:layout_gravity specifies the alignment for the View within the parent, android:gravity specifies the alignment of the Views contained within the View whose gravity you are specifying. Make sure you have the proper one specified. The documentation does not distinguish between these two.
It would be easier to help you if you posted some sample XML.
EDIT:
I see you have posted the XML now. It does look like you have the proper attribute set, but if you are aligning the text to the right, why would you put it first in the linear layout? I suggest changing it to go left to right.
Here is some code I wrote for my project. It accomplishes what you're looking for. I'd just change the control types and such and you should be off and running.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#ffdddddd">
<TextView android:layout_width="260dp"
android:layout_height="wrap_content"
android:text="More Comments"
android:textStyle="bold"
android:background="#ff0000"
android:textColor="#121222"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<ImageView android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="#drawable/arrow_right"
android:scaleType="centerInside"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>