I'm creating checkboxes in 2 diffent ways:
1) XML
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-10dp"
android:id="#+id/checkBox1" />
2) Java-code
CheckBox myCheckBox = new CheckBox(this);
myLayout.addView(myCheckBox);
And the look differently
The one from code:
And from XML:
Why is that?
And how can I make them equal?
I think it could be because the XML version is newer whereas the Java version draws an older version of a checkbox from an older android. I would suggest just using either Java or Xml for both. Keep them the same
Related
I need an bar as like as image.
User can pull it and change value.
I need xml or java code for android studio.
You are looking for a SeekBar
Here's a XML code
<SeekBar
android:id="#+id/simpleSeekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Any opdates? I hope my answer helped you
I made an Activity in Android Studio and added a button in there, added the constraints so the error would go away. When I run an App from Android Studio to my phone, it works fine. When I use an AAR file in Unity and call the activity from there, the buttons jump back to 0,0 like the error said if I did not add constraints, which I did. I'm not getting any errors either as to why it's not able to constraint the button.
Here is how I made the button in my activity.
activity_main.xml
<Button
android:id="#+id/button"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginBottom="431dp"
android:layout_marginEnd="130dp"
android:layout_marginStart="168dp"
android:layout_marginTop="32dp"
android:text="#string/StringName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I've never really worked with Android Studio UI until now, so I might have forgotten something important here, just hoping one of you guys knows what could be the problem, thanks in advance.
EDIT
The problem is with "app:", everywhere you use it should be replaced with "android:". However android:layout_constraintBottom_toEndOf="parent" doesn't work. Instead you have to use: android:layout_alignParentEnd="true". Also replace "android.support.constraint.ConstraintLayout" with "RelativeLayout".
Unity doesn't work with "app:" for some reason so replacing with "android:" is always necessary. Thanks Soon Santos for telling me about RelativeLayout, I looked at this: https://developer.android.com/guide/topics/ui/layout/relative.html and remembered I had gotten an app: problem before and fixed by changing to android:.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.Company.MainActivity">
<Button
android:id="#+id/button"
android:layout_width="86dp"
android:layout_height="wrap_content"
android:layout_marginStart="168dp"
android:layout_marginTop="25dp"
android:text="#string/StringName"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="false"/>
</RelativeLayout>
You can actually leave out android:layout_alignParentEnd/Start. With RelativeLayout it seems to not jump back to 0,0 at all, so basically always use android: and RelativeLayout when using Unity (it seems like that at least).
Nothing wrong with the code, it works for me too. Maybe it is because your other way to run the code does not support constraintLayout, you can try RelativeLayout instead and see if it'll work.
I am trying to do a build for android on codenameone , after the last update when I send a build for android it converts all buttons and label text to UPPERCASE
whatever the text [was written in]
any build hint or fix to this issue
Regards,
See this for the long version https://www.codenameone.com/blog/pixel-perfect-material-buttons.html
Here is the short version, you can disable this using:
myButton.setCapsText(false);
Button.setCapsTextDefault(false);
Define the theme constant capsButtonTextBool to false
According to the latest Material Design guidelines, buttons use ALL CAPS for text, regardless of the capitalization you pass in.
https://material.io/guidelines/components/buttons.html#buttons-style
To prevent this, set this attribute on your <Button> tag:
android:textAllCaps="false"
Try this ,
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAllCaps="false"
android:text="#string/button" />
I've seen most of post # stackoverflow and i've done as told.
Create new xml (tried a few different samples)
But i can't change the background in activity xml, it does not want to find "#drawable/shape"
I have the new xml in right folder and I'm struggling with it since this morning. I'd be more than glad to see some help ;)
Sorry, I've got it like that:
'
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chest"
android:id="#+id/button"
android:textColor="#android:color/black"
android:layout_gravity="center"
android:textSize="23sp"
android:layout_toStartOf="#+id/maxWagi"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/maxWagi"
android:background="#drawable:button_shape"'
// <----- if I change it to some #color it's working just fine.
and my xml button_shape is in app\src\main\res\xml\ (android studio put it over there by itself) I even added manually drawable folder like in most tutorials but it does not change anything
You have syntax mistake. Your background should be #drawable/button_shape instead of #drawable:button_shape. Also put in a drawable folder in res.
I have made a listitem, containing a title and a subtitle. Looking to the result, I think it doesn't look really professional. So that's why I'm asking.
The listitem I'm looking for is pretty common (it's used in a lot of apps i.e. Android's default settings menu and it's also shown when you add a listview in the graphical layout editor tab in eclipse).
So my question is: Where can I find a default layout for a listitem with a title and a subtitle?
Resource id is android.R.layout.simple_list_item_2
Upper text line has id android.R.id.text1 and lower one - android.R.id.text2
Layout is located in the <ANDROID_SDK_ROOT>/platforms/<any_api_level>/data/res/layout folder
OR
You can use TwoLineListItem from the default Android controls list(it is located under "Advanced" tab in Eclipse Layout Editor)
OR
You can build your own layout with anything you like(for example LinearLayout with orientation="vertical" and two TextEdits added
So The Best Way Is:- I took out the simple list item 2 and made an layout in my project and with little editing it took the same layout as you may give in android.R.simple_list_item_2
So the code is:-
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/listPreferredItemHeight"
android:mode="twoLine"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingEnd="?attr/listPreferredItemPaddingRight"
android:paddingRight="?attr/listPreferredItemPaddingRight">
<TextView android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView android:id="#id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/text1"
android:layout_alignStart="#+id/text1"
android:layout_alignLeft="#+id/text1"
android:textAppearance="?attr/textAppearanceListItemSmall" />