I'm wondering how can I create something like this photo, I can do it by creating two of TextView but is there any easier way, or is there an external library?
You can use Android Textview attributes just like shadowDy shadowDx and shadowRadius.I hope it might be helpful for you.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="#string/shadow"
android:textSize="80sp"
android:textStyle="bold"
android:shadowColor="#7000"
android:shadowDx="12"
android:shadowDy="12"
android:shadowRadius="8"/>
and You can also check it from this link there are some slides related to textview styles https://chiuki.github.io/advanced-android-textview/#/8
Related
I'm trying to make an app like the one in this mockup:
Supermarket
It's a very simple supermarket app. As you can see, there's a TextView at the bottom of the screen that tells me whether my Cart is empty, or has items in it. If the cart is not empty, the user is shown the total price he/she must pay. You can also notice that said TextView's style and text change according to a variable (in this case, "totalPrice").
How can I do this in Android? I know I can use simple if statements (if totalPrice == 0, then backgroundColor = grey and text = "EmptyCart", for example), but this seems somewhat... hardcoded. Is there a better way to do it? As you can see, the TextView's style and values also change when on the "Subproducts" activity (some Products have Subproducts, which you can see after clicking on them).
Thanks in advance!
I think Databinding is the best way rather than boilerplate code.
create a model class and change background of the view using ternary operation in databinding also manage visibility of price text using this.
To set a textview's text, you use textView.setText("new text"); To set its background, its textView.setBackgroundColor(color) where the color is the hexcode you want as an integer- for example 0xFFFF0000 for reg. Obviously these can be variables as well as hard coded.
It can simply be achieved with two TextViews in a RelativeLayout, and of course, by using basic TextView's methods. As an example layout:
<RelativeLayout
android:layout_height="75dp"
android:layout_width="match_parent"
android:background="#1EC4F3">
<TextView
android:text="PAY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:typeface="sans"
android:textColor="#FFFFFF"
android:textSize="18sp"/>
<TextView
android:layout_height="wrap_content"
android:text="$25.79"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:typeface="monospace"
android:textSize="14sp"
android:textColor="#FFFFFF"/>
</RelativeLayout>
When I place a button in a layout, it has a standard gray background. However I want to make it more like the kind of button you see in the Dialogs where it's a background-less button (e.g. the white buttons with text).
Like this
Not like this... not like this...
Old question but I just stumbled on it and have the answer (or at least I think), I really don't know if that's the best approach, but it should do the job.
<Button
android:id="#+id/sign_in_button"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
The trick here is the #style/Widget.AppCompat.Button.Borderless.Colored. Also see this answer, it explains a lot https://stackoverflow.com/a/36666660/1920068
try this
android:background="#android:color/transparent"
Just use a TextView instead, and put a click effect with the background:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#23ac29"
android:text="Signup"
android:textSize="18sp"
android:padding="8dp"
android:background="?android:attr/selectableItemBackground"/>
I want to create special characters for math, for an android application. And I wonder if it's is possible to overlay one character on top of another, or if there is some fine control on how text is rendered (and how do you go about doing that).
If you need a general method to display math equations, have a look at jqMath. I think you can render it using a WebView.
Many math symbols have Unicode code points. Specifically, the Unicode code point for the symbol of a '+' inside a circle is U+2295. They can be rendered directly if the font supports it. For a list of some math symbols with corresponding Unicode code points check this Wikipedia article.
Also have a look at this question for resources using MathML in Java.
I would extend the View class and then use the drawText method of the Canvas object you receive in the onDraw method. It sounds like you need fine control over coordinates of where text is being painted and extending View would give you just that. Take a look at Canvas.drawText and you can use the x and y coordinates to overlay text as you require.
Try this:
This way you can add Superscript text :
TextView out_unit2 = (TextView) findViewById(R.id.out_unit2);
out_unit2.setText((Html.fromHtml("meter<sup><small>2</small></sup>")));
Subscript text :
TextView out_unit2 = (TextView) findViewById(R.id.out_unit2);
out_unit2.setText((Html.fromHtml("meter<sub><small>2</small></sub>")));
You can use this to add as many to your code.
Hope it helps you.
Thanks.
It could get really messy really quickly, but you would be able to accomplish it with a FrameLayout and several TextViews inside. For example, XML for a "0" overlapped with a "+", superscript "+" and subscript "-":
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="#dimen/title_bar_font_size" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textSize="#dimen/title_bar_font_size" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textSize="12sp"
android:layout_marginLeft="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textSize="12sp"
android:layout_marginLeft="12sp"
android:layout_gravity="bottom" />
</FrameLayout>
Resulting in:
This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.
Excuse my next picture, done in a hurry :):
Please can anybody tell me how can I use Layouts and TextViews in Android to get something similar with I draw.
The box with one TEXT is a String and also the box with TEXT TEXT TEXT is a String.
Thank you.
I don't thing you can use 2 TextView instances for this situation. A workaround could be to use only one TextView and do your text formatting programmatically.
In the RelativeLayout, inside each TextView tag use these attributes as per your requirement
android:layout_below="Id of the TextView"
android:layout_above="Id of the TextView"
android:layout_toLeftOf="Id of the TextView"
android:layout_toRightOf="Id of the TextView"
something like this should do the trick. The keys are layout_below and layout_toRightOf
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="#+id/LeftTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingRight="10dp" android:paddingBottom="10dp"
android:text="HI">
<TextView android:id="#+id/WholeTextView"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_below="#id/LeftTextView"
android:layout_toRightOf="#id/LeftTextView">
</RelativeLayout>
For some reason, that's a bad approach even if it works. I would suggest use a different textview for the bottom row. It may work with some combination in Relative Layout, but it may probably not be the same in each and every screen/resolution.
Have you tried using compound drawables?
textview2.setCompoundDrawables(textview1, null, null, null);