How can I change the font size in Android Studio? - java

I don't want to change the font size of Android Studio itself, but rather the font size of the app i'm working on. All the search results I have found talk about the user interface or zooming in.
I'm Working on a tic-tac-toe beginner project and the button text always is so small. Any tips on how to increase it?
Here is its part in the xml file:
<Button
android:id="#+id/button_0"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
Many thanks in advance for anyone who helps

Add android:textSize property into Button, eg:
<Button
android:id="#+id/button_0"
android:layout_width="0dp"
android:textSize="20sp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
https://developer.android.com/reference/android/widget/TextView#attr_android:textSize

One way is to change the textSize attribute in the XML file. The other way is to mention it in the program.
Button btn = findViewById(R.id.button_0);
btn.setTextSize(20.0f);
where btn is the name of the button.
Note: The size mentioned in the setTextSize() method must be a float value.

Related

Remove Extra Space between Views

I'm building a simple calculator app and i cannot get ride of extra grey lines next to an ImageButton
Button Code
<Button
android:id="#+id/button_clear"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/white"
android:text="AC"
android:textColor="#color/indigo"
android:textSize="18sp" />
ImageButton Code
<ImageButton
android:id="#+id/button_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/backspace"
android:background="#color/white"/>
As you can see, the buttons are perfect but the ImageButton have grey lines next to them.
I tried settings the Parent background to 'White' and setting the ImageButton background to '#null' too
I tried an Imageview and the Problem still exists
i tried setting the image as background to the button and it still exists
i even tried setting negative margin towards left and right and the problem still exists
Can someone help me out please?
Add this in your ImageButtons
style="?android:attr/borderlessButtonStyle"
I have a suggestion: Use a button to display the ⌫ symbol. For information on how to get the desired results visit: How to make ⌫ symbol backward-compatible in Android Studio?

Android: Scale background image of RadioButton or another way to make a RadioButton an Image

I'm making an app that is related to a card game and as such has many images of cards appear throughout the app. In one section I need the user to select one of four cards, with only one selection ever being possible and I want to have the card to change color slightly after being clicked to show that it is the currently selected one.
For the bulk of this task a RadioGroup with RadioButtons makes perfect sense since the functionality for having a checked/unchecked state and unselecting all other options when a new one is picked is built in; however, the issue is that I want the buttons to be the cards themselves and therefore an image with no text whatsoever.
At first this post looked promising: Adding custom radio buttons in android
My use of this strategy:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_weight="5"
android:orientation="horizontal">
<TextView
android:id="#+id/label_seatGod"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"
android:gravity="center_vertical"
android:text="#string/ex2"
android:textColor="#color/font_condition_labels"
android:textSize="#dimen/font_gen_label_size"
android:textStyle="bold" />
<RadioGroup
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8" >
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#drawable/power_aphrodite"
android:checked="false"
android:text="#null" />
</RadioGroup>
</LinearLayout>
which resulted in:
This is almost perfect. No text and the entire region of the clickable button space is composed of the image I want, EXCEPT that as you can see the image is not scaled at all and is cropped on the edges. Above the RadioButton you can see a LinearLayout with 4 ImageButtons that demonstrate exactly how I want the RadioButton/card image to appear (ignore the grey for now I haven't finished padding the views).
Essentially, I want a RadioButton that functions normally but looks exactly like one of the four ImageButtons in the top section. Ideally scaleType="fitCenter" would be the fix since it is what I am using in the example ImageButtons, but you cannot apply that attribute to the button drawable of a RadioButton or its background directly.
So how can I get the image to scale and not be cropped without resorting to some performance tanking layout jurry rigging or creating an entirely new RadioButton class?
Thanks in advance.
Maybe you could try adding this to your RadioButton in the xml:
android:scaleType="centerCrop"

Put a text on top of a button - android

i have a regular android button
<Button
android:id="#+id/btn_0"
style="#style/def_button_numb"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="0" />
First:
I need to put some text on top of this button, just like keyboards does.
And second:
On longpress needs to show a popup (also like keyboards), to let user choose two more options of buttons.
is there an ease way to do so?
you can simply add this code
android:text="SEND DATA TO FRAGMENT B"

Which layout in android studio to use for placing precisely clip arts

I have a viewpager that recreate parallax effect using ViewPager.PageTransformer()
I have a clip art made of several pieces (clouds, tree etc...) that i have to place very precisely on a layout of one of my fragment, so can animate them later independently , but i'm unable to place any item precisely. On a relative layout, it seems that each time i move one items with the mouse, it goes either right , left, or top etc.., i want to be able to place them pixels by pixels, a bit like a puzzle
Is there any any layout (mspaint style) i could use that would let me place freely my item using my mouse for example, without having to obey any rules of placement ?
Thanks a lot
I have been able to use RelativeLayout in Android Studio to place items precisely. The images to tend to "snap" along grid lines when close, but I think that with careful mouse movement you can make it work. This will be very dependent upon the screen size and will not scale up/down well since it is using margins, but it may be what you need.
Here is the layout I tested with in Android Stdio 2.1. I hope this helps.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageView1"
android:layout_width="219dp"
android:layout_height="219dp"
android:background="#00FF00"
android:layout_marginRight="26dp"
android:layout_marginEnd="26dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="58dp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="219dp"
android:layout_height="219dp"
android:background="#FF0000"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="53dp"
android:layout_marginStart="53dp" />
</RelativeLayout>

SeekBar pointer not in the centre Android Studio Java

I am making a SeekBar in my Android Java application for the first time, but the slider circle is not in the middle of the line as I would expect, but a little above it. I can't figure out why this is the case.
There is an image of the slider at http://i.stack.imgur.com/AAGkM.jpg
My layout for the slider is:
<SeekBar
android:layout_width="match_parent"
android:id="#+id/seekBar"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#ffff4007"
android:progress="0"
android:max="100"/>
You can post the code of your layout to better help you, maybe you can try this
android:gravity="center"
To do this use
android: progress=0
In java use
Seekbar.setmax(to set maxm value..as integer);

Categories