I've TextView. I need to make it clickable, white and with "selectable effect", besides I need it to have a rectangular white border, to fake a button borders:
<TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:background="#drawable/white_empty_rectangle"
android:clickable="true"
android:padding="10dp"
android:text="Test"
android:textColor="#color/white" />
I can't set two background properties...how can I somehow "intersect" the two properties?
EDIT: I only need the borders of the rectangle, so it is "empty", I should see the background color behind the TextView.
Check this answer https://stackoverflow.com/a/5295522/4848308 you should use background selector.
This one to achieve border line background https://stackoverflow.com/a/3496310/4848308
I hope it helps!
What about this?
<FrameLayout
android:id="#+id/frame_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground"
android:clickable="true">
<TextView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/rectangle_empty_white"
android:padding="8dp"
android:text="#string/test"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="14sp" />
</FrameLayout>
Related
How can I add a black and solid outline border to a textView.
I tried this code:
<TextView
android:id="#+id/faqTitle"
style="#style/viewParent.headerText.HomeCardTitle"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:shadowColor="#color/colorRed"
android:shadowRadius="15"
android:paddingBottom="#dimen/padding"
android:paddingStart="#dimen/padding"
android:paddingEnd="#dimen/padding"
android:textColor="#color/colorWhite"
android:text="TEST" />
The problem is that after updating showRadius, the outline is not solid.
I don't want to use an external library. Only uses of XML attributes.
Please take a look at the attached images.
Expected
Actual
For outline to characters you can use below code
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/test1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="TEST"
android:textColor="#000000"
android:textSize="25sp" />
<TextView
android:id="#+id/test2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="TEST"
android:textColor="#FFC107"
android:textSize="25sp" />
</FrameLayout>
In .java file put these lines to give border to TextView characters
TextView textViewShadow = (TextView) view.findViewById(R.id.test1);
textViewShadow.getPaint().setStrokeWidth(5);
textViewShadow.getPaint().setStyle(Paint.Style.STROKE);
I want to have a button like this.
It's basically a Text: NEXT with a Chevron on the right side.
I already tried a button with transparent background and android:drawableRight, but the padding of the drawable was looking weird.
How can I achieve the wanted look?
What I have so far:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:textColor="#color/colorAccent"
android:drawableRight="#drawable/chevron_right"
android:background="#00000000"/>
/Sorry for posting a link and not the photo directly, but my reputations aren't high enough./
You can do it using a FrameLayout/RelativeLayout containing the ImageButton and an horizontal LinearLayout/RelativeLayout which contains the text and the chevron image aligned to the right. Something like this:
<FrameLayout
android:id="#+id/fl_btn_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/imbtn_btn_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/white_drawable" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="#+id/tv_btn_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:gravity="center_horizontal"
android:text="#string/next" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/tv_btn_text"
android:src="#drawable/chevron" />
</RelativeLayout>
</FrameLayout>
This example is from my app, probably you'll need to adapt it.
Have you tried setting the spaces between the views of chevron and borders with negative values of dp .
I had a similar problem last year and a proper combination of positive and negative dp fixed it
You can use android:drawablePadding="8dp" to set the padding between the text and the drawable.
I'm not sure what you want but that's how I will do the button you attached
<RelativeLayout
android:layout_width="80dp"
android:background="#color/colorAccent"
android:layout_height="40dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NEXT"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/arrow_up_float"/>
</LinearLayout>
</RelativeLayout>
i want to remove default right shadow in a Button but i don't know how to do it, i tried also to set his background transparent, but it didn't work.
I'll post here my code and what i'm getting now.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/rel1"
android:background="#drawable/search_rounded" <!-- drawable background with blue gradient-->
android:padding="3dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textView"
android:text="Latest Chapters"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#0361c9"
android:padding="5dp"
android:gravity="center"
android:layout_toLeftOf="#+id/backToTopBtn"
android:layout_toStartOf="#+id/backToTopBtn"
android:background="#drawable/edittext_rounded" <!--white background with rounded corners-->
android:layout_marginRight="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Back to top"
android:id="#+id/backToTopBtn"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:background="#android:color/transparent"/> <!--setting right button's background transparent-->
</RelativeLayout>
I want to remove that shadow line between textview and button
put
android:background="#null"
I'm using a ViewFlipper to alternate some different RelativeLayouts. My layout is very simple.
<RelativeLayout
android:id="#+id/display_info_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:text="#string/information"
android:color="#color/black" />
</RelativeLayout>
THE PROBLEM:
The color named "black" is defined in my resources as "#000000". The text elements appear the correct black color in other layouts, but in this one it appears a dull grey.
Other Layout
This Layout
THE QUESTIONS:
What could be causing this?
How do I fix it?
You should be using android:textColor I don't think android:color exists as an attribute
So:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:text="#string/information"
android:textColor="#color/black" />
ContextCompat.getColor(getContext(), color) fixed the issue for me
I've two ListViews in a single LinearLayout. The background of LinearLayout is a drawable. Everything is working fine, but when I do fling on any of the ListView, the background image disappears and the black background is shown. When fling stops the image gets shown again as a background. I don't want to change the background, Am I doing anything wrong?
The Layout is as following:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:text="Upcoming Trips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/top_blue_box"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="16sp"
android:layout_gravity="center"
/>
<ListView
android:id="#+id/upList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
/>
<TextView
android:text="Past Trips"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bottom_box"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="16sp"
android:layout_gravity="center_horizontal"
/>
<ListView
android:id="#+id/downList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="2"
/>
</LinearLayout>
EDIT:
The solution is explained here in details, thanks to Robinhood.
use
listView.setCacheColorHint(Color.TRANSPARENT);
in java or
android:cacheColorHint="#00000000"
inside ListView tag in xml
Apply same color cache hint to listview as your layout color.
Example:
android:cacheColorHint="light blue"
Cache Color Hint