How do I make an Android SeekBar? - java

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

Related

How to make steps bar in android like Bootstrap

Hello Is there anyway or library that can help me create like this image of bootstrap steps progress bar in android with text and icon ???
Use stepView
<com.baoyachi.stepview.HorizontalStepView
android:id="#+id/step_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
Reference : 1.https://github.com/baoyachi/StepView, 2.https://github.com/shuhart/StepView 3.https://github.com/shadowsong91/StepView

Creating UI in Android Studio and using it in Unity makes elements jump to 0,0

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.

Can't get rid of the ugly border around ImageButton

I'm working on an Android App which has a few (Next, Back, ... etc) Buttons which are all round and transparent and I use ImageButton for those Buttons, however the problem is there is always a white border around the Button (I use black background so it is very ugly) and the button never appears to be round is appears as some sort of a square-ish shape.
Here is what I tried so far :
Setting the background of the ImageButton in the activity_mypage.xml file to
android:background="#android:color/transparent"
and to
android:background="?android:selectableItemBackground"
and to
android:background="?android:selectableItemBackgroundBorderless"
even to
android:background="#null"
but nothing seems to work on the .xml side.
and I tried the following on the MyPage.java file :
myBtn.setBackgroundResource(0);
and also
myBtn.setBackground(null);
Nothing seems to work anything I do keeps resulting the same (although it removes a gray border from around the Button but none of them makes the Button completely transparent)
This is a screenshot of the button before applying any of above :
And this is a screenshot of the same Button after applying any of those attributes (doesn't really matter if I applied it only to the xml or only to the java file or to both because all results are the same):
This is my xml code for one of my Buttons in xml :
<ImageButton
android:id="#+id/my_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="26dp"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#mipmap/my_btn"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintRight_creator="1"
android:background="#android:color/transparent"
/>
And here is the code for it in the .java file :
ImageButton myBtn= (ImageButton) findViewById(R.id.my_btn);
myBtn.setBackground(null);
myBtn.setBackgroundResource(0);
I'm really lost at this every result I found for this query has suggested one of the above methods but none of these seems to work for me..
Just change
android:background="#android:color/transparent"
to
android:background="#null"
Try with this
android:src="#mipmap/yourimage"
instead of
app:srcCompat="#mipmap/my_btn"
add this to your button
android:background="#drawable/template"
and create a file name it template in your drawable folder
and add this code to it
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="#drawable/btn2imagePressed"></item>
<item android:drawable="#drawable/btn1imageNotPressed"></item> </selector>
You can use ImageView instead of ImageButton, so background issue will not occur
<ImageView
android:id="#+id/my_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="26dp"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:src="#mipmap/my_btn"
/>
So after reading some of the posted answers and playing around with the suggestions in my code I noticed that the icon was incorrectly loaded into my mipmap directory instead of drawables and that is because when I imported the icons I selected New -> Image Asset instead of Vector Asset which caused my 'icon' to lose its transparency ...
Thanks to everyone for their replies and answers.

Android Studio 0.8.9 How to change buttons shape?

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.

Fragments are not running perfectly in real device

I have used fragments to define a simple splitview, in the right site i used a layout containing videoview the xml code is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="#+id/tvT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
and in the left site in another fragment layout I have defined some buttons to play different videos, The program is running well in emulators, but when I run it on device, the videoview overlapped the whole area and creates a horrible look, what should I do?
You need to post more of your code if you can; what you have posted isn't really enough for people to help you. [Edit: Darn, I thought this was trivial enough to be automatically moved to a comment on the original question :-\ ]
May you could try with "fill_parent" because the video could be to big and uses the hole display:
<VideoView
android:id="#+id/tvT"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
If you can it would be good if you post some code how you setup your fragments.

Categories

Resources