I'm developing an Android Hybrid App for Tablets (Android WebView with local HTML5 Website). Inside my WebApp is a DatePicker
<input type="date">
Which looks like this:
It's very tiny on that big screen. So I was wondering if it's possible to increase the font size of that date picker or even to make it full screen.
Also is there a way to change the Theme of the DatePicker? I prefer a bright theme over that dark one.
Thank you in advance.
As i understood u want to increase size of font ... visit this link
<style name="datepickerstyle" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/colorPrimary</item>
<item name="colorControlActivated">#color/colorPrimaryDark</item>
<item name="android:editTextStyle">#style/editTextStyle</item>
</style>
<style name="editTextStyle" parent="android:style/Widget.EditText">
<item name="android:textColor">#color/colorTextPrimary</item>
<item name="android:textSize">#dimen/text_20</item>
</style>
<DatePicker
android:theme="#style/datepickerstyle"
android:id="#+id/timepicker" android:timePickerMode="spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
update try below code to resize font
DatePicker picker = (DatePicker)findViewById(R.id.dp_date);
ViewGroup childpicker
= (ViewGroup)
findViewById(Resources.getSystem().getIdentifier("month" /*rest is:
day, year*/, "id", "android"));
EditText textview = (EditText)
picker.findViewById(Resources.getSystem().getIdentifier("timepicker_input",
"id", "android"));
textview.setTextSize(30);
textview.setTextColor(Color.GREEN);
///or u can below also
ViewGroup childpicker = (ViewGroup)datePicker.findViewById(Resources.getSystem().getIdentifier("month", "id", "android"));
EditText mornthEt = (EditText)childpicker.getChildAt(1);// month widget
//change textsize and textcolor for mornthEt
mornthEt.setTextSize(30);
mornthEt.setTextColor(Color.GREEN);
Related
I have a LinearLayout with that has multiple TextViews and want to set up a default global color for that layout only without having to add a textColor field inside each TextView. Also, if it's possible, would it also be possible to override the color value by adding it inside the TextView? i.e. If I set blue as a default color and black for a single TextView, would the blue change to black?
To set the default global TextView colors, first you can create your own theme in AndroidManifest.xml file for the following items:
textColorPrimary - for Large texts
textColorSecondary - for Medium texts
textColorTertiary - for Small texts
textColorHint - for Hint texts
For example, in AndroidManifest.xml:
<style name="TextViewTheme" parent="android:Widget.TextView">
<!-- Set the default global color for TextViews to Holo Blue Dark -->
<item name="android:textColorPrimary">#android:color/holo_blue_dark</item>
<item name="android:textColorSecondary">#android:color/holo_blue_dark</item>
<item name="android:textColorTertiary">#android:color/holo_blue_dark</item>
<item name="android:textColorHint">#android:color/holo_blue_dark</item>
</style>
Next, set the theme style on your LinearLayout. You can also override the default for a single TextView to black color, like the following which set the first TextView Hint text color to black in activity_main.xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="#style/TextViewTheme">
<TextView
android:id="#+id/phone_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/phone_tv"
android:textColor="#android:color/black"
android:textColorHint="#android:color/black" />
<TextView
android:id="#+id/email_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/email_tv" />
</LinearLayout>
Hope this helps!
You can override default text colors for the entire application by setting textColorPrimary and textColorSecondary in your parent in styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="textColorPrimary">#color/black</item>
<item name="textColorSecondary">#color/grey</item>
</style>
If your TextViews are indeed very many to the extent that calling setTextColor() on each of them would be a herculean task, why not use a view that supports an adapter (i.e ListView, RecyclerView etc). Your TextViews would show up the exact same way as you intend them to appear with the LinearLayout.
While using an adapter, you can set up a model TextView layout and set a global textColor for all the TextViews. You can override this global textcolor in your adapter by using simple if and else statements.
I hope this helps.. Merry coding!
This code will work even if you add or remove TextViews from your layout. Just put it in your activity's onCreate();
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
for (int i = 0; i < layout.getChildCount(); i++) {
View v = layout.getChildAt(i);
if (v instanceof TextView) {
((TextView) v).setTextColor(Color.BLACK);
}
}
change the color to what you like.
If you want after this code you can change the color for any specific TextView.
Pretty late answer but this does the trick.
Inside style.xml lately changed to themes.xml
<style name="ErrorStyle">
<item name="android:textColor">#FF0000</item>
</style>
Then inside your xml layout
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="#style/ErrorStyle">
.. All of your TextView
</LinearLayout>
Using this approach we can use other xml variation such as night mode, etc... and we still have te possibility to override the internal TextViews.
How to decrease padding in NumberPicker
I want something like it:
It's surprisingly easy to archive:
(scaleX and scaleY equals 2.5)
(without scaleX and scaleY)
String[] values = {"Public", "Shared", "Private",....};
NumberPicker np=
(NumberPicker) findViewById(R.id.numberPicker);
np.setMaxValue(values.length-1);
np.setMinValue(0);
np.setDisplayedValues(values);
And simply set small layout_height and scaleX, scaleX:
<NumberPicker
android:id="#+id/numberPicker"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:scaleX="2.5"
android:scaleY="2.5"/>
I do agree, that standard NumberPicker is hardly customizable, though.
I hope, it helps
Unfortunately, number picker is not style-able.
I advise on using a library such as the one by SimonTV
This is probably a bit late but you can set the explicit height on the NumberPicker it then follows the given height and adjusts the space between the items.
As Grebulon pointed its very simple to customize the picker if you are using the libray by .
These are the code and the results-
<net.simonvt.numberpicker.NumberPicker
android:id="#+id/numberPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:internalMaxHeight="100dp"
app:selectionDividersDistance="30dp"/>
I was forked it once to increase the number of selector wheels.
Here is the output of above code.
Try to customize your NumberPicker Theme like below:
<style name="Widget.Holo.NumberPicker" parent="Widget.NumberPicker">
<!-- Customize your theme here -->
<item name="android:selectionDivider">#android:drawable/numberpicker_selection_divider</item>
<item name="android:selectionDividerHeight">2dp</item>
<item name="android:selectionDividersDistance">25dp</item>
<item name="android:internalMinWidth">50dp</item>
<item name="android:internalMaxHeight">100dp</item>
</style>
Hope it's help your.
A simple solution is to decrease the height of the NumberPicker that will result in decrease of internal spacing between the numbers as well, in my case I have set it to 120dp and that just does the job
android:layout_height="120dp"
Here is the complete code for my NumberPicker
<NumberPicker
android:id="#+id/numberPicker"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginEnd="16dp"
android:theme="#style/myNumberPicker" />
For styling I have used the following theme in my style file
<!-- Custom style for Number Picker -->
<style name="myNumberPicker" parent="Theme.MyApplication">
<item name="android:textSize">26sp</item>
<item name="android:textColorPrimary">#color/textColorBlue</item>
<item name="colorControlNormal">#android:color/transparent</item>
<item name="android:fontFamily">#font/montserrat_semi_bold</item>
</style>
I have a dialog box that I create to display messages in android. It basically contains a text view in a scrollview like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/about_msg"
android:text="#string/about_msg"
android:autoLink="web"
android:padding="10dip"
style="#style/DialogTextSmall" />
</ScrollView>
As you can see I have applied a style to TextView the style looks like this
<style name="DialogTextSmall">
<item name="android:textSize">#dimen/text_size_small</item>
</style>
The application theme set is like this
<style name="AppTheme" parent="android:Theme.Light">
The Problem:
On ICS api-15 it shows fine black text on white background of TextView.
The problem is When I show dialogbox in Froyo its the text does'nt seem to show even though it seems to have taken space - My guess is the color of text is same as background (greyish black)
I know I can quick fix by hard-coding black background and white text, but Is it not possible to have the default colors of platform for the text color and background of the TextView to appear, without me having to hardcode them ?
You can inherit a parent style and then only change the values you want to change. Try changing your XML to this:
<style name="DialogTextSmall" parent="#android:style/Widget.TextView>
<item name="android:textSize">#dimen/text_size_small</item>
</style>
The list of styles you can inherit can be found in the AOSP source on Github here.
EIDT:
By default text views have black text and transparent background, so you will need to set one or the other if the background behind the text view (which, again, is transparent) is black.
Inheritance from Textview style did not really help. It is a little quirky problem and here is one way to do it
http://blog.andromo.com/2011/fixing-text-colours-on-an-alertdialog-when-using-theme-light/
In my case I did it another way
Solved it for theme I inherited it from default android theme
<style name="Theme" parent="android:Theme"></style>
<style name="Theme.AppTheme" parent="#android:style/Theme.Light"/>
and
<style name="DialogTextSmall">
<item name="android:textSize">#dimen/text_size_small</item>
<item name="android:textColor">#android:color/white</item>
</style>
This way for all platforms , froyo, gingerbread and above, the dialog boxes are black and text is white on them
The default textsize in datepicker is too big for my app. I've seen a way suggested to change it here, but fishing around for the textviews nested inside the datepicker class seems clunky and error prone.
Is there a better/cleaner way to do it?
Setting a theme to DatePicker layout and adding android:textSize to it works for me.
In your layout's xml add a DatePicker applying a theme as shown below -
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="#style/NumberPickerStyle"
android:datePickerMode="spinner"
android:calendarViewShown="false"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
and then define the NumberPickerStyle in styles.xml specifying android:textSize like this -
<style name="NumberPickerStyle">
<item name="android:textSize">#dimen/number_picker_text_size</item>
</style>
The easiest way to change the font size of datepicker/timepicker/numberpicker is customizing the theme.
In styles file, set the default font size in the following way.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:textSize">22sp</item>
</style>
Sean's approach made some glitches in the UI of picker itself in case there're a number of pickers and I think it's not perfect to apply text size to all the components under the picker.
Below is what I've used and it works perfect without any UI glitches.
<style name="PickerTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:editTextStyle">#style/PickerEditText</item>
</style>
<style name="PickerEditText" parent="ThemeOverlay.AppCompat.Dark">
<item name="android:textSize">24sp</item>
</style>
Sean's code works. but it is changing font size for all the other components also(textViews, buttons, etc...) So Here is the solution.
Create different style for time picker and use it on time picker theme.
<style name="my_time_picker_style">
<item name="android:textSize">24sp</item>
</style>
and use it on your timepicker
android:theme="#style/my_time_picker_style"
Look at video, how I did https://youtu.be/JMJ2ujhk9c0
use below code:
ViewGroup childpicker = (ViewGroup)datePicker.findViewById(Resources.getSystem().getIdentifier("month", "id", "android"));
EditText mornthEt = (EditText)childpicker.getChildAt(1);// month widget
//change textsize and textcolor for mornthEt
mornthEt.setTextSize(30);
mornthEt.setTextColor(Color.GREEN);
use below code
DatePicker picker = (DatePicker)findViewById(R.id.dp_date);
ViewGroup childpicker
= (ViewGroup)
findViewById(Resources.getSystem().getIdentifier("month" /*rest is:
day, year*/, "id", "android"));
EditText textview = (EditText)
picker.findViewById(Resources.getSystem().getIdentifier("timepicker_input",
"id", "android"));
textview.setTextSize(30);
textview.setTextColor(Color.GREEN);
I'm trying to get a text box that looks like a spinner to activate a date picker dialog. This is done in both the Google Calendar app and the Contacts app (for birthdate) on ICS. Do I need to use a spinner, and if so how do I change it's input view to be a date picker? Or if not, how do I get a text view to have the little triangle that usually indicates a spinner?
Twaddington's comment on his answer is actually the right approach.
What you need is to create a text view and apply the style
style="#android:style/Widget.DeviceDefault.Light.Spinner"
Then you can create a click listener on the text view and use it to open a DatePickerDialog. That can be accomplished as shown here: https://stackoverflow.com/a/8127571/332738
(If you follow the example, remember to add a default constructor to DatePickerDialogFragment so that your app does not crash on rotate)
I don't know if you still need this. But in the Contacts app, it is achieved with the following:
<Button
...
style="?android:attr/spinnerStyle"
... />
This should work over all Android versions, as it is available since api level 1:
http://developer.android.com/reference/android/R.attr.html#spinnerStyle
I'm not sure if this is what you're asking, but you should be able to follow the Date Picker tutorial on the Android developer website.
Also, the DatePicker and DatePickerDialog classes might be worth a look.
I would prefer below theme for Spinner like google contacts.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:spinnerStyle">#style/AppTheme.Form.Spinner</item>
<item name="android:spinnerItemStyle">#style/AppTheme.Form.Spinner.Item</item>
</style>
<!-- Spinner Styles -->
<style name="AppTheme.Form.Spinner" parent="Widget.AppCompat.Spinner">
<item name="android:paddingRight">0dp</item>
<item name="android:paddingEnd">0dp</item>
</style>
<style name="AppTheme.Form.Spinner.Item" parent="Widget.AppCompat.EditText">
<item name="android:clickable">false</item>
</style>
</resources>