I am using AppCompatCheckBox in XML layout as given below,
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/checkBox"
android:buttonTint="#color/appColor"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp" />
But the check box is not visible on device running 4.3. But CheckBox text is visible, but not the CheckBox. Whats wrong here?
I am following this link. See the answer with 5 Points.
I don’t know if this solves, but you don’t need to use AppCompatCheckBox; a simple CheckBox is enough.
The activity you are using, presumably an AppCompatActivity, automatically inflates layout checkboxes as AppCompatCheckBoxs.
AppCompat* widgets should be used only when creating views at runtime, e.g. new AppCompatCheckBox(context) or when subclassing.
Related
I am trying to do some simple app to practice, and the user interface gets broken for some reason I don't know why when I run test on my phone. I did an app on android only once before and I didn't have this problem, I was using a different phone though. I'm testing this on Samsung Galaxy A5.
That's how it looks in project: http://imgur.com/Pnbg5ns
And that's how it looks on my phone: http://imgur.com/a/uki84
Anyone knows how to resolve this?
All your views have locations set with the tools:... attribute. The locations set this way (using tools:) position the views within the Android Studio editor, and Android Studio editor only. It doesn't do anything at all to position the views for when the app is actually run, that's why all your views are on top of each other, they simply don't have any attributes to indicate their positioning on the screen when the app is run.
You should check tutorials for how to use ConstraintLayout (if you want to use that layout) which is a recent (2016) addition to Android and position your views with the constraints you need. Or you could use some of the older layouts like LinearLayout which should be perfectly fine for your layout needs.
And absolute positioning of the views like you have with the use of the tools:... attribute is also a big no most of the time. Views need to be positioned in some relative way within a layout, which doesn't mean it has to be within a RelativeLayout :), just saying that the views should be positioned in reference to the layout containing them, not just at some absolute point f.e. (150, 110).
This is a very simple layout. You can use LinearLayout instead of ConstraintLayout.
Here is an example using LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="16dp">
<EditText
android:id="#+id/etLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Login"
android:inputType="textPersonName" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Hasło"
android:inputType="textPassword" />
<Button
android:id="#+id/bLogin"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Loguj"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/tvRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Nie masz jeszcze konta? Kliknij tutaj."
android:layout_gravity="center_horizontal"/>
</LinearLayout>
OUTPUT:
Hope this will help~
When using a checkbox with extra drawable (besides the one used for the checkbox) using drawableLeft, the two drawables overlapp one another.
There is nothing special about the checkbox settings, here:
<CheckBox android:id="#+id/low_priority_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/low_priority"
android:textColor="#color/primary_text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:drawableLeft="#drawable/ic_primary_priority_flag_low_medium"/>
Actual result:
Expected result:
This problem occurs with compileSdkVersion 22 on devices with API <= 16
By the way, using drawableRight works as it should.
Is this a bug in the framework?
Any workaround?
Add style (style="#android:style/Widget.Holo.Light.CompoundButton.CheckBox") for the checkbox, which can move the drawable to correct position. The only issue is the distance between drawable and text is bigger than normal case for devices with API <= 16.
One of my CheckBox xml is listed as the following:
<CheckBox
android:id="#+id/male_toilet_checkbox"
style="#android:style/Widget.Holo.Light.CompoundButton.CheckBox"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:drawableLeft="#drawable/m"
android:drawableStart="#drawable/m"
android:text="#string/male_toilet"
android:textSize="14sp"
android:textColor="#ff6c51ff"
app:layout_constraintTop_toBottomOf="#+id/split_line1" />
I'm having a changeable text like in the screenshot, where the quantity changes according to plus and minus buttons.
What is the best to implement that on Android ?
Could I make use of Spannable text in this case ? Or do I implement that with
a vertical LinearLayout with a TextView then a separator view then another TextView that changes ?
If you want to make it your own way, look for click events on the plus and minus buttons, change an integer variable (say mQuantity) according to these click event (mQuantity++ or mQuantity-- respectively), and change the TextView content with mQuantityLabel.setText(mQuantity+"");. That extra +"" is to avoid setText looking for a probably non existing id inside strings.xml. You could just need to convert the int to String, but this suffices for this case.
However, and it may be more sensible to go for already established solutions for number increase/decrease such as NumberPicker (after API 11) or SimonVT's NumberPicker (backport of NumberPicker, if the minSdkVersion is prior to API 11).
Managed to achieve this layout, using LinearLayout.
It was straightforward I thought that it might need tricky layout technique, but turned out to be easy.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quantity"
android:textAppearance="#android:style/TextAppearance.Medium" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/black" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="01"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
When im designing my android app im using XML and for this app im using the Relative layout but when i put the buttons on my screen with the png background i made its just looking bad.. the buttons are not put equaly like they should..
Look at this picture:
How would i solve so the pluss buttons and percent and comma and equal button will be placed right instead of looking all that weird?
If you are intrested to see my XML code here is an link for pastebin:
http://pastebin.com/gpxnPT4P
I think you have to check the android:layout_... of every item that is showing wrong. For example, the declaration for the number 5 button is:
<Button android:background="#drawable/number5" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:id="#+id/number5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="#+id/number8" android:layout_alignLeft="#+id/divided"></Button>
If you look closely the android:layout_alignLeft declaration is pointing to de divide button (#+id/divided) that is far away. There is a similar situation with the button for number 6.
Try this declaration for number 5 button:
<Button android:background="#drawable/number5" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp" android:id="#+id/number5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="#+id/number8" android:layout_alignLeft="#+id/number4"></Button>
Hope this helps
I am looking for a view or some sort of information regarding the bottom bar in default applications of Android such as Email, or Unlock pattern as shown in the picture below. I have not been able find anything about this on Androids site nor from Google searches.
Image: http://img11.imageshack.us/i/viewdn.jpg/
I believe that Christopher is correct; there is no special widget to create the bar in your image. However, if you want to emulate it, you can create a layout and use the style style="#android:style/ButtonBar". That will give you the light gray background and the correct margins.
I don't believe there's any standard view for the button bar used at the bottom of these apps; it's generally just two Button items placed together in a LinearLayout or RelativeLayout.
For example, looking at the Android Open Source Project, you can see the button bar for one of the email app setup screens is defined as two plain old Button objects.
However, it is surprising that Google didn't abstract more of the common stuff into an Android theme or sublayout, rather than having the same views and attributes in each layout XML.
From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314
<RelativeLayout
android:layout_marginTop="-45dip"
android:padding="0dip"
android:layout_alignParentBottom="true"
android:gravity="bottom|right"
android:background="#android:drawable/bottom_bar"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button
android:id="#+id/manual_setup"
android:text="#string/account_setup_basics_manual_setup_action"
android:minWidth="#dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-4dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="false"
/>
<Button
android:id="#+id/next"
android:text="#string/next_action"
android:minWidth="#dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableRight="#drawable/button_indicator_next"
android:layout_marginBottom="-4dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="false"
/>
</RelativeLayout>