I am expreiencing a strange problem with my application. When I am testing it on a real device (with Android 4.4.4) all my Buttons' text fields look how I wanted (lower case letters). But when I launch my application on an emulator (Android 5.0.1) all Button texts fields are capitalized. What is the reason of such behaviour? Some example Buttons from my app:
Example Button 1:
<Button
android:id="#+id/button5"
android:layout_width="match_parent"
style="?android:attr/borderlessButtonStyle"
android:layout_height="wrap_content"
android:text="#string/finish"
android:textColor="#FFFFFF"
android:textSize="30sp"
/>
Example button 2:
<Button
android:id="#+id/button3"
android:layout_width="0dp"
style="?android:attr/borderlessButtonStyle"
android:layout_height="wrap_content"
android:text="#string/flower"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:drawableLeft="#drawable/flower"
android:layout_weight=".75"
/>
What is the solution to this problem. I want my app to look the same on all sw versions.
Starting with Android 5.0, Buttons automatically have their text capitalized. This is in accordance with the new material design guidelines, which you can find here.
If you want to force your buttons to display the text as it does in previous platform versions, you can set android:textAllCaps="false" in your XML. However, I would recommend against this. Users expect their apps to look material in Android Lollipop, and that means they expect your buttons to display text in all capital letters (even if your app displays the text differently in previous platform versions).
Actually this is possible:
new AlertDialog.Builder(context, R.style.StackedAlertDialogStyle)
StackedAlertDialogStyle:
<style name="StackedAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="buttonBarButtonStyle">#style/StackedButtonBarButtonStyle</item>
</style>
<style name="StackedButtonBarButtonStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:layout_gravity">right</item>
<item name="android:textAllCaps">false</item>
</style>
Now you can see the buttons not in capital.
Related
In my current project I have about 10 buttons that are almost the same. I'm looking for a way to reuse the code for these buttons.
I've tried to move part of code to separate layout and reuse it via <include... layout=...>, but no success.
I use binding in the project and the compiler does not allow me to cast this View to TextView for calling it from the code. I've tried to move part of this code and set it as a style. No way :-( I have a few selectors here (for different states including enabled and disabled). However, they don't work.
<TextView
android:id="#+id/tv_next_button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp"
style="#style/Myfont_Bold"
android:layout_gravity="center_horizontal"
android:background="#drawable/selector_button_next_bg"
android:drawablePadding="36dp"
android:letterSpacing="-0.01"
android:lineSpacingExtra="3sp"
android:padding="#dimen/padding_15"
android:text="#string/next"
android:textColor="#drawable/selector_button_next_font"
android:textSize="#dimen/text_16"
app:drawableEndCompat="#drawable/selector_button_next_arrow"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/ll_switchers"/>
Any ideas?
I don't want to copy-paste this code 10 times.
Create a style for reused styled Views and apply it in every layout it used
<style name="MyCustomStyle" parent="DesiredParentStyleFromLibrary">
<item name="attribute1">value</item>
<item name="attribute2">value</item>
<item name="attribute2">value</item>
// and so on
</style>
I want to achieve a look like this (from the material design specs) for my switch when it's in the off state:
notice that the thumb is white and has a black outline with a slight shadow. I haven't been able to replicate this at all - much less to replicate the "focused" and "pressed" states with the halo around the thumb. What is the correct way of doing this? Do I need to work with 9-patches or is there a way to do it just using themes and xml? I want to support api 16 and up, but I noticed that Switch supports 14 and up so that shouldn't in itself be an issue.
Code for my current switch:
<Switch
android:id="#+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
/>
In my app Styles.xml:
<item name="colorControlActivated">#color/myColor</item>
<item name="colorSwitchThumbNormal">#android:color/white</item>
<item name="android:colorForeground">#android:color/white</item>
hi i am using android:textIsSelectable="true" to enable copy menu feature on text view it is working on android 4.2 jellybean but when trying this on lollipop menu appear for a second and auto disappear.is there any thing that i am missing in xml on i have to add in class file associated with XML
<TextView
android:id="#+id/singleMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text="MyMsg"
android:longClickable="true"
android:autoLink="web"
android:textAppearance="?android:attr/textAppearanceSmall"/>
If you app theme extends one of .NoActionBar themes, you need to enable windowActionModeOverlay, to fix this issue.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionModeOverlay">true</item>
</style>
Try, and check the android docs link for details.
android:setTextIsSelectable="true"
http://developer.android.com/reference/android/widget/TextView.html#setTextIsSelectable(boolean)
I am developing a simple app in Android Studio, and I am testing it on a real device (Asus zenfone 5 & Android 4.4.2). In the main activity I have applied this layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="madapps.mysecondapp.MainActivity"
android:id="#+id/activity_main" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"
android:orientation="horizontal"
android:background="#drawable/background_deathstar">
<EditText
android:id="#+id/edit_message"
android:text="#string/message" android:layout_weight="1"
android:layout_width="0dp" android:layout_height="wrap_content"
android:hint="#string/edit_message" android:textColor="#FFF" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
with this style.xml applied to the activity
<resources>
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
What I want to do is testing a background image on different screen sizes and densities (dpi).
Now, the problem is that while in my physical device the property
android:windowActionBarOverlay
is applied properly, laying out my action bar on top of my background image, this is not working equally within Android Studio's layout editor, meaning that my image begins at the end of the action bar.
ps. I have also noticed that apart from ignoring the windowActionBarOverlay property, my action bar fails to load my custom action buttons. I think these two problems are somewhat related.
Any suggestions?
Thank you very much
Apparently I should have not expected Android Studio's layout editor to reflect what I'm seeing on devices, because it's only using a subset of the real Android layout system.
Actually my action bar is hidden and shown programmatically, and the layout editor is only supposed to serve as a way to drag-and-drop widgets and preview a layout while editing the XML.
I try to make some XML layout in Android Studio. I need my app to be compatible with API 10 and higher. My layout have some switch buttons but Switch is for API 14 or higher. It is why I decide to use Toggle Button instead.
I have made custom selector drawable with two states. And problem starts now.
When I make XML like this:
<ToggleButton
android:id="#+id/reminderRepeatToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/toggleButton"
android:button="#drawable/ic_toggle_bg"
android:background="#android:color/transparent"/>
It works perfectly on android higher than API 10 but on 10 ToggleButton simply disappear.
I also tried something like this:
<ToggleButton
android:id="#+id/reminderRepeatToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/toggleButton"
android:background="#drawable/ic_toggle_bg"/>
and it works on API 10 but it looses it proportions. Any idea how to overcome this? Or maybe you advice different approach to the problem? (not making Toggle but something different).
Thanks for help!
style:
<style name="toggleButton">
<item name="android:buttonStyleToggle">#style/Widget.Button.Toggle</item>
<item name="android:textOn">#string/blank</item>
<item name="android:textOff">#string/blank</item>
</style>
<style name="Widget.Button.Toggle" parent="android:Widget">
<item name="android:background">#drawable/ic_toggle_bg</item>
<item name="android:disabledAlpha">?android:attr/disabledAlpha</item>
</style>