I am going through quickstart for androidPlot. http://androidplot.com/docs/quickstart/
In the example simple_xy_plot_example.xml layout file is defined with parameters such as
androidPlot.titleWidget.labelPaint.textSize="#dimen/title_font_size"
androidPlot.domainLabelWidget.labelPaint.textSize="#dimen/domain_label_font_size"
androidPlot.rangeLabelWidget.labelPaint.textSize="#dimen/range_label_font_size"
androidPlot.graphWidget.marginTop="20dp"
androidPlot.graphWidget.marginLeft="15dp"
androidPlot.graphWidget.marginBottom="25dp"
But where are these parameters defined? I mean how do I know to use titleWidget.labelPaint.textSize to define textSize?
Define these variables in res/values/dimens.xml like this
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="title_font_size">16dp</dimen>
<dimen name="domain_label_font_size">12dp</dimen>
<dimen name="range_label_font_size">12dp</dimen>
<dimen name="range_tick_label_font_size">12dp</dimen>
<dimen name="domain_tick_label_font_size">12dp</dimen>
<dimen name="legend_text_font_size">12dp</dimen>
</resources>
Where domain_label_font_size is the value you want to define.
Related
In material design 3, there are 15 types of typography tokens:
textAppearanceDisplayLarge (57sp)
textAppearanceDisplayMedium (45sp)
textAppearanceDisplaySmall (36sp)
textAppearanceHeadlineLarge (32sp)
textAppearanceHeadlineMedium (28sp)
textAppearanceHeadlineSmall (24sp)
textAppearanceTitleLarge (22sp)
textAppearanceTitleMedium (16sp)
textAppearanceTitleSmall (14sp)
textAppearanceBodyLarge (16sp)
textAppearanceBodyMedium (14sp)
textAppearanceBodySmall (12sp)
textAppearanceLabelLarge (14sp)
textAppearanceLabelMedium (12sp)
textAppearanceLabelSmall (11sp)
Here is how I used the tokens:
values\dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textSizeDisplay">36sp</dimen>
<dimen name="textSizeHeadline">24sp</dimen>
<dimen name="textSizeTitle">14sp</dimen>
<dimen name="textSizeBody">12sp</dimen>
<dimen name="textSizeLabel">11sp</dimen>
</resources>
values-large\dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textSizeDisplay">45sp</dimen>
<dimen name="textSizeHeadline">28sp</dimen>
<dimen name="textSizeTitle">16sp</dimen>
<dimen name="textSizeBody">14sp</dimen>
<dimen name="textSizeLabel">12sp</dimen>
</resources>
values-xlarge\dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textSizeDisplay">57sp</dimen>
<dimen name="textSizeHeadline">32sp</dimen>
<dimen name="textSizeTitle">22sp</dimen>
<dimen name="textSizeBody">16sp</dimen>
<dimen name="textSizeLabel">14sp</dimen>
</resources>
Depending on the text type, I use the tokens
<com.google.android.material.textview.MaterialTextView
...
android:textSize="#dimen/textSizeTitle" />
The question:
Did I use the tokens in the right way or there is another way to use the tokens?
Also, I know when I should use Display and Body, But when should I use Headline, Title, and Label because I think they are the same?
I read this and this but still don't know when should I use Headline, Title, and Label.
Thank you.
I have been overriding the space between my menu icons and menu text for sometime now but, when I migrated to androidx the override seems to be no longer working. Any idea on how to override them on androidx?
Here is my current override on dimens.xml
<dimen tools:override="true"name="design_navigation_icon_padding">10dp</dimen>
<dimen tools:override="true"name="design_navigation_icon_margin">5dp</dimen>
Here you can find the attributes used in the new NavigationView in the Material Components for Android library.
<dimen name="design_navigation_max_width">280dp</dimen>
<dimen name="design_navigation_elevation">16dp</dimen>
<dimen name="design_navigation_item_icon_padding">32dp</dimen>
<dimen name="design_navigation_item_horizontal_padding">16dp</dimen>
<dimen name="mtrl_navigation_elevation">0dp</dimen>
<dimen name="mtrl_navigation_item_icon_padding">14dp</dimen>
<dimen name="mtrl_navigation_item_icon_size">24dp</dimen>
<dimen name="mtrl_navigation_item_horizontal_padding">22dp</dimen>
<dimen name="mtrl_navigation_item_shape_horizontal_margin">8dp</dimen>
<dimen name="mtrl_navigation_item_shape_vertical_margin">4dp</dimen>
However the best way to change these values is to use the xml attributes like itemIconPadding in the layout.
Something like:
<com.google.android.material.navigation.NavigationView
...
app:itemIconPadding="#dimen/myvalue"/>
You can use new material NavigationView with app:itemIconPadding:
<com.google.android.material.navigation.NavigationView
...
app:itemIconPadding="#dimen/navigation_icon_padding"/>
dimens.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="navigation_icon_padding">12dp</dimen>
</resources>
What is the meaning of this line of code?
android padding Right = "# dimen /activity_horizontal_margin".
What is #dimen referring to?
you use the dimens file like this so that you can easily set many things to the same value (like a constant in code), or so you can override the value easily for different screen sizes.
dimen is located in / res / values / in studio project like below
dimen.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="action_button_min_width">56dp</dimen>
<dimen name="indeterminate_progress_size">32dp</dimen>
</resources>
Learn more about project structure in android studio
https://developer.android.com/studio/projects/index.html
dimen.xml is the file which you can set constant values for dimensions.
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
It is usually created inside /res/values folder. If you don't find it there you can create and add values.
You may refer the following link for more details.
https://developer.android.com/samples/BasicSyncAdapter/res/values/dimen.html
I was wondering if it is possible to make a dimension a multiple of another dimension in Android. E.g., so I can do something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="base">50dp</dimen>
<dimen name="size_of_something">4*#dimen/base</dimen>
</resources>
Right now, I use a workaround like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="base_x1">50dp</dimen>
<dimen name="base_x2">100dp</dimen>
<dimen name="base_x3">150dp</dimen>
<dimen name="base_x4">200dp</dimen>
<!-- etc... -->
<dimen name="size_of_something">#dimen/base_x4</dimen>
</resources>
But this means that I have to update all the multiples every time I change the base size, which is not only cumbersome, but also error-prone.
Based on here on XML Attributes section I specify following in my dimens.xml:
<dimen name="match_parent">-1dp</dimen>
<dimen name="main_left_menu_user_account_width">#dimen/match_parent</dimen>
<dimen name="main_left_menu_user_account_height">#dimen/match_parent</dimen>
Then I use the both dimensions in my layout:
<ImageView
android:id="#+id/userAccountImage"
android:background="#drawable/user_account"
android:layout_width="#dimen/main_left_menu_user_account_width"
android:layout_height="#dimen/main_left_menu_user_account_height" />
Then, when I preview to Graphical Layout, it complains:
You must supply a layout_width attribute.
You must supply a layout_height attribute.
Actually can I define a value equals to match_parent in dimens.xml?
Update:
I also tried this but the preview still complains:
<dimen name="main_left_menu_user_account_width">-1dp</dimen>
<dimen name="main_left_menu_user_account_height">-1dp</dimen>
I successfully use wrap_content (the Graphical Layout doesn't complain at all):
<dimen name="wrap_content">-2dp</dimen>
<dimen name="main_right_menu_width">#dimen/wrap_content</dimen>
<dimen name="main_right_menu_height">#dimen/wrap_content</dimen>
Use this, it works for me
<dimen name="custom_wrap_content">-2px</dimen>
<dimen name="horizontal_border_height">#dimen /custom_wrap_content</dimen>
<dimen name="custom_match_parent">-1px</dimen>
<dimen name="vertical_border_height">#dimen /custom_match_parent</dimen>
And the Reason why match_parent doesn't run. You cannot supply a build in keyword like match_parent
Edit: Use px instead of dp as suggested by Jarett Millard in the comments.
First create attribs.xml:
<resources>
<item name="match_parent" type="dimen">-1</item>
<item name="wrap_content" type="dimen">-2</item>
</resources>
Second use your dimens:
<dimen name="account_width">#dimen/match_parent</dimen>
<dimen name="account_height">#dimen/wrap_content</dimen>
Depending on why you want to define match_parent in a #dimen, this use case could help you:
Instead of defining the width and height in dimen.xml, you can define it as a style in the styles.xml
I use
//res/values/styles.xml
<style name="IntroLayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
and
//res/values-sw600dp/styles.xml
<style name="IntroLayout">
<item name="android:layout_width">520dp</item>
<item name="android:layout_height">wrap_content</item>
</style>
and use it like
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
style="#style/IntroLayout">
which allows me to dynamically set the width and height attributes for different sized devices without having to write any code and you can use match_parent/wrap_content fine. you can use any #dimen that you have defined previously in the style as well if you want.
I use this because the layout for phone and tablet is the same, except i want to fix the width on tablet but fill the parent on phone, so it saves having to have 2 different layouts with basically the same xml
For HTC devices use this to achieve match_parent:
<dimen name="my_match_parent">-1.0px</dimen>
You can also achieve this using integers.xml file
integers.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="match_parent">-1</integer>
<integer name="wrap_content">-2</integer>
</resources>
Use in dimens.xml:
<dimen name="main_right_menu_width">#integer/wrap_content</dimen>
You might also get lint warning, to suppress it use:
<dimen name="main_right_menu_width" tools:ignore="ReferenceType">#integer/wrap_content</dimen>
I don't think so. #dimen/match_parent is a specific length with unit while match_parent is a special flag.