I have this textview which is white in color and I am putting on top of an image with lighter background. The problem is that the text "My App" is barely visible. Is it the contrast or what do I have to change on textview to stand the bright white color out? If the background color of image is dark then the white color stand out but in this case it almost blends.
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/skyline"
tools:context=".SplashActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/size_75dp"
android:text="My App"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:layout_gravity="center_horizontal|top" />
</android.support.design.widget.CoordinatorLayout>
Add a translucent background to your TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/size_75dp"
android:text="My App"
android:textColor="#FFFFFF"
android:background="#30000000"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="60sp"
android:layout_gravity="center_horizontal|top" />
Edit: based on your comment, look at the Palette library.
If I were in your situation, I'll try to tackle the issue by handling both image and text, since we might have a bright background with a white text or vice Versa.
First, we'll make sure our image background is dark enough to let our white textView visible clearly, I recommend to apply a light overlay upon the imageview (Framelayout with top image) or even use the alpha attribute.
Now that our image is arranged, we should do the same for the textview but this time using shadows, like the following
android:shadowColor="#000000#"
android:shadowDx="0"
android:shadowDy="2"
android:shadowRadius="20"
Change the above values according to your needs.
Hope that answers your question.
Related
I have set both the CardView's background and FrameLayout's to transparent yet the result is still a white color bg.
Is this some default behavior? What should I change to my xml layout file for having a transparent bg ?
Layout file :
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardBackgroundColor="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="140dp"
tools:layout_gravity="center">
<TextView
android:id="#+id/dayID"
android:textColor="#color/link_text_material_light"
android:textSize="26dp"
android:layout_marginLeft="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/monthID"
android:textColor="#color/link_text_material_light"
android:layout_marginLeft="60dp"
android:textSize="26dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/splashID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/link_text_material_light"
android:textSize="26dp"
android:layout_gravity="center"
android:gravity="center"
android:padding="20dp"
tools:text="Hero text" />
<TextView
android:id="#+id/sunbathMinsID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/link_text_material_light"
android:textSize="26dp"
android:layout_gravity="bottom"
android:gravity="center"
android:padding="20dp"
tools:text="Hero text" />
</FrameLayout>
</android.support.v7.widget.CardView>
A transparent background can be obtained for any number of views within your XML.
This is a decent explanation for an imageview.
Set transparent background of an imageview on Android
Cardviews are a lot the same but have a little different attribute and are explained very well with the "app:cardBackgroundColor= "#android:color/transparent""
See this post for that type of attribute.
Transparent background on CardView - Android
Setting your cardView and the subsequent FrameLayout both to transparent will definitely get the job done and make both views transparent. However, the activity will always have a solid background. The Activity only doesn't have a solid background when you set a resource as the background and the views placed within that Activity will show the current background if they are set to transparent as seen in the links above.
Therefore, even though you have set your "views" to transparent, the Activity will always need a color or image to show the in background. Meaning that, yes you will still have a white background behind your cardView, unless you change that color.
I created a personal keyboard and set the background image to the one of the buttons, but after that button size (with my background) is different from one another.
<Button
android:id="#+id/buttonShift"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
Set background:
<Button
android:id="#+id/buttonShift"
android:background="#drawable/sym_keyboard_shift_off"
android:paddingTop="0dip"
android:textSize="22sp"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:textStyle="bold" />
Please, see the screen of the buttons
Before:
After:
Image size: 106x68
I would advise you to:
Change your drawable a bit - remove the orange rectangle background, keep only the arrow with transparent background (from now on I will use the name shift_off_arrow as a name of described drawable). The transparent background should be only as big as it is needed to keep the whole arrow. Not bigger.
Define a new color - the color of your orange background (from this moment I will assume you have defined it and I will be using name orange_background)
Use ImageButton instead of Button (just like satnam singh and Hamid Shatu said in a comments to your question)
Use code like this (manipulate with all paddings to get the size of the arrow exactly like you want):
<ImageButton
android:id="#+id/buttonShift"
android:background="#color/orange_background"
android:src="#drawable/shift_off_arrow"
android:paddingTop="0dip"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1" />
The images shown below are in PNG format, with transparent background.
I used a TextView per item which consists of a DrawableTop image and Text. I wanted my image to be transparent but it is not working properly. I tried alpha method for transparency but the entire TextView will lighten. I wanted just the image, not the entire TextView.
By the way, I used TextView instead of a LinearLayout per item consisting of an ImageView and TextView because the IDE prompted me with a warning and I was advised not to have any warning in my code.
I have the following code in Android:
<TextView
android:id="#+id/marketBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1"
android:background="#drawable/unselected_button"
android:drawableTop="#drawable/market_icon_0"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="5dp"
android:text="#string/task_bar_lbl_market"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"
android:textSize="13sp" />
I am now confused what to do next. Should there be any help, I will be much grateful! For more info, here's a screen cap of this bug:
Use Button instead of TextView :
<Button
android:id="#+id/marketBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/show"
android:layout_alignLeft="#+id/name"
android:layout_marginBottom="36dp"
android:background="#drawable/unselected_button"
android:drawableTop="#drawable/market_icon_0"
android:text="#string/task_bar_lbl_market"
android:textColor="#FFFFFF"
android:textStyle="bold" />
You must combine background and drawableTop style.
You don't need image transparent for background.
You can used #ARGB [int alpha, int red, int green, int blue]
<item name="android:background">#0000</item>
<item name="android:drawableTop">#drawable/btn_setting</item>
Below is how I have designed my xml. Now what I am trying to fit a textview inside the white box shown below. But am being restricted by FrameLayout (at least I think so) that I need to hard code values to make the text view fit in the middle or some where inside the white box. I cannot use Relative or other layouts for this purpose as I have understood by my trials as this whole is a single image.
Here is my layout,
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:visibility="visible" android:layout_marginTop="60dip"
android:layout_gravity="center" android:id="#+id/xxx">
<ImageView android:id="#+id/calloutquizImage"
android:background="#drawable/callout" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:scaleType="fitCenter" />
<ImageView android:id="#+id/triviaImage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/calloutquizImage" android:layout_gravity="left"
android:src="#drawable/trivia" android:background="#drawable/trivia"
android:layout_marginTop="50dip" android:layout_marginLeft="85dip"></ImageView>
<TextView android:text="TextView" android:id="#+id/triviAnswerText"
android:layout_marginTop="125dip" android:layout_marginLeft="85dip"
android:layout_gravity="left" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#000000"
android:typeface="sans"></TextView>
<ImageButton android:id="#+id/triviaanswercloseButton"
android:src="#drawable/closebtn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="#drawable/closebtn"
android:layout_marginRight="8dip" android:layout_marginTop="43dip"
android:layout_gravity="right" android:onClick="triviaanswerClose"></ImageButton>
<ImageView android:id="#+id/buttontoclose"
android:layout_gravity="left"
android:visibility="visible" android:onClick="triviaanswerClose"
android:layout_marginTop="50dip" android:layout_marginLeft="75dip"
android:layout_width="230dip" android:layout_height="170dip"></ImageView>
</FrameLayout>
Because of this the text view looks in different positions in various handsets.
Any guesses what can be done for this instead?
Below is my image :
I think you are not doing the right thing. If you want a text to appear inside a white box (or even resize it, if there is to many text to fit to it) - you can still avoid any layouts ad do it with only one TextView.
Please have a look what is NinePatch image in Android:
http://developer.android.com/reference/android/graphics/NinePatch.html
http://developer.android.com/tools/help/draw9patch.html - drawing tools
So basically you will need only 1 textView and your image, properly converted to 9-patch with 2nd link. (Basically - just add a few black pixels on image border).
No just set this 9-patch as a background of textView. It will place text right where you need, and will shrink white box if you'll define so in 9-patch.
UPD:
Please find the resulting screenshot:
As you can see, textView not handles
WhiteBox" itself, filling it with text and resizing the box if necessary.
Here is how to make it work:
<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">
<TextView
android:id="#+id/first"
android:background="#drawable/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Manymanymany text
Manymanymany text
Manymanymany text
Manymanymany text
Manymanymany text
Manymanymany text" />
<TextView
android:layout_below="#+id/first"
android:background="#drawable/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not so many text" />
</RelativeLayout>
And here is your image, converted to 9patch. Just place it to "drawable/" folder. Note: it MUST have "back.9.png" name.
For details of how 9patch works you can check links above. The main idea: by making black dots on left and top border - you specify which part of the image will be stretched when image must be upscaled. By making dots on right/bottom side you tell the View where to place the content. In our case content is a text of the TextView.
Hope it helps, good luck
I think you can use a RelativeLayout within the FrameLayout for the ImageView and the TextView, and by using the parameters, you can navigate the TextView to the white box. Refer to the LayoutParams documentation for details.
for eg. you can add the ImageView block first and then the TextView, so that the TextView will lay over the ImageView, and by using align bottom, and specifying top margin with a negative value, you can make the TextView go over the image. Or rather, if you are using eclipse, you can directly move the text view in the graphic layout.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:id="#+id/xxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:visibility="visible" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margintop="0dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/user2" />
<TextView
android:id="#+id/Textviewtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:layout_below="#+id/imageView1"
android:layout_marginTop="-10dp"
app:context=".TestActivity" />
</RelativeLayout>
</FrameLayout>
Similar to above, you can specify margin left and right to properly position your TextView as you want. Check with graphic layout for feedback to know the correct position.
Please reply if this helped.
Use your images and values for the height and width. I just tried for testing.
I have a TextView with a background that declared as:
<TextView
android:id="#+id/questionText"
android:layout_width="250dp"
android:layout_height="100dp"
android:gravity="center"
android:textSize="26px"
android:textColor="#FFFFFF"
android:background="#drawable/blue"
/>
the problem is that the background image is like a frame, so i want the
text inside to have a margin from the background image dimensions.
Is this possible?
10X alot,
have a gr8 weekend :)
What you want sounds like padding.
<TextView
android:id="#+id/questionText"
android:layout_width="250dp"
android:layout_height="100dp"
android:gravity="center"
android:textSize="26px"
android:textColor="#FFFFFF"
android:background="#drawable/blue"
android:padding="5dp"
/>
This would put a 5 pixel border around the actual text showing the background through.
Incidentally, layout_margin is also a parameter and is used to put space between the entire view, background included, and other views.
I'd recommend to make 9-patch drawable. It defines where the text can be without specifying padding in the control.