How can I do to define "when it's a 600dp use this size for the action bar, when it's 720 dp this other one". Will this also resize the icons??
In order to customize the size of the Action Bar for different screen sizes, you need to create a number of copies of styles.xml
in your values
folder. Then, customize the size of the the action bar under the theme declaration tag. Like if you want to set the Action Bar size at 600dp, do it like this:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarSize">600dp</item>
</style>
In this way you can have different action bar sizes for different screen sizes. And you can have as many of them as you want.
Hope this helps.
EDIT :
To have more control over the action bar you must replace your action bar with the new Toolbar.
Make Toolbar
in your res/layout/my_layout.xml
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary" />
and again in your res/layout-large-land/my_layout.xml
or res/layout-large/my_layout.xml
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="200dp" //different height because for layout-large-land
android:layout_width="match_parent"
android:background="?attr/colorPrimary" />
then in your activity's onCreate()
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
setSupportActionBar(toolbar);
will replace your ActionBar
with the Toolbar
! Now you can have different attributes within your different xml's
Also make sure the Theme you apply to your activity has NoActionBar
Attribute
<style name="Theme.MyTheme" parent="Theme.AppCompat.NoActionBar">
To add more.. You can read more about the android-design-support-library from the official blog post.
OLD :
The android documentation on supporting different devices is the appropriate approach to follow! You can have a good read from supporting-devices and tablets-and-handsets
And specifically for supporting different screen sizes
To optimize your user experience on different screen sizes, you should create a unique layout XML file for each screen size you want to support. Each layout should be saved into the appropriate resources directory, named with a - <screen_size>
suffix. For example, a unique layout for large screens should be saved under res/layout-large/
.
MyProject/
res/
layout/ # default (portrait)
main.xml
layout-land/ # landscape
main.xml
layout-large/ # large (portrait)
main.xml
layout-large-land/ # large landscape
main.xml
and for icons
You should always provide bitmap resources that are properly scaled to each of the generalized density buckets: low
, medium
, high
and extra-high
density. This helps you achieve good graphical quality and performance on all screen densities.
MyProject/
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
drawable-ldpi/
awesomeimage.png
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.