Mark Murphy - Beginning Android

Здесь есть возможность читать онлайн «Mark Murphy - Beginning Android» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: New York, Год выпуска: 2009, ISBN: 2009, Издательство: Apress, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Beginning Android: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Beginning Android»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Master Android from first principles and begin the journey toward your own successful Android applications!
Dear Reader,
First, welcome to the world of Android! We’re entering a new era of mobile application development, one marked by open platforms and open source, to take ‘walled gardens’ and make them green houses for any and all to participate in. Android is relatively easy for developers, and I believe that this innovation will help generate a large ecosystem of developers and consumers within a very short time. This means that budding developers such as yourself will have many opportunities to design and build your own applications and you’ll have a huge and hungry customer base.
Second, welcome to the book! Its purpose is to start you on your way with building Android applications, and to help you master the learning curve. Android is already a rich framework, comparable in many ways to the richness Android of desktop Java environments. This means that there is a lot of cool stuff for you to pick up along your journey in order to create the slickest, most useful apps Android you can imagine.
The source code for the code samples in this book is all available from the Apress site, so you can stay as hands-on and practical as you like while I introduce you to the core of Android, and invite you to experiment with the various classes and APIs we’ll be looking at. By the time you’ve finished this book, you’ll be creating your own Android applications and asking yourself what your next great application will be…!
Enjoy! Mark Murphy

Beginning Android — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Beginning Android», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Love the One You’re With

Android natively knows three fonts, by the shorthand names of “sans”, “serif”, and “monospace”. These fonts are actually the Droid series of fonts, created for the Open Handset Alliance by Ascender. [14] http://www.ascendercorp.com/oha.html

For those fonts, you can just reference them in your layout XML, if you so choose. The following layout from the Fonts/FontSamplersample project shows example code, and can also be found in the Source Code area at http://apress.com:

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="1">

android:text="sans:"

android:layout_marginRight="4px"

android:textSize="20sp"

/>

android:id="@+id/sans"

android:text="Hello, world!"

android:typeface="sans"

android:textSize="20sp"

/>

android:text="serif:"

android:layout_marginRight="4px"

android:textSize="20sp"

/>

android:id="@+id/serif"

android:text="Hello, world!"

android:typeface="serif"

android:textSize="20sp"

/>

android:text="monospace:"

android:layout_marginRight="4px"

android:textSize="20sp"

/>

android:id="@+id/monospace"

android:text="Hello, world!"

android:typeface="monospace"

android:textSize="20sp"

/>

android:text="Custom:"

android:layout_marginRight="4px"

android:textSize="20sp"

/>

android:id="@+id/custom"

android:text="Hello, world!"

android:textSize="20sp"

/>

This layout builds a table showing short samples of four fonts. Notice how the first three have the android:typefaceattribute, whose value is one of the three built-in font faces (e.g., “sans”).

The three built-in fonts are very nice. However, it may be that a designer, or a manager, or a customer wants a different font than one of those three. Or perhaps you want to use a font for specialized purposes, such as a “dingbats” font instead of a series of PNG graphics.

The easiest way to accomplish this is to package the desired font(s) with your application. To do this, simply create an assets/folder in the project root, and put your TrueType (TTF) fonts in the assets. You might, for example, create assets/fonts/and put your TTF files in there.

Then, you need to tell your widgets to use that font. Unfortunately, you can no longer use layout XML for this, since the XML does not know about any fonts you may have tucked away as an application asset. Instead, you need to make the change in Java code:

public classFontSampler extendsActivity {

@Override

publicvoid onCreate(Bundle icicle) {

super. onCreate(icicle);

setContentView(R.layout.main);

TextView tv = (TextView) findViewById(R.id.custom);

Typeface face = Typeface. createFromAsset( getAssets(),

"fonts/HandmadeTypewriter.ttf");

tv. setTypeface(face);

}

}

Here we grab the TextViewfor our “custom” sample, then create a Typefaceobject via the static createFromAsset()builder method. This takes the application’s AssetManager(from getAssets()) and a path within your assets/directory to the font you want.

Then, it is just a matter of telling the TextViewto setTypeface(), providing the Typefaceyou just created. In this case, we are using the Handmade Typewriter [15] http://moorstation.org/typoasis/designers/klein07/text01/handmade.htm font (see Figure 12-1).

Figure 121 The FontSampler application Note that Android does not seem to - фото 49

Figure 12-1. The FontSampler application

Note that Android does not seem to like all TrueType fonts. When Android dislikes a custom font, rather than raise an Exception, it seems to substitute Droid Sans (“sans”) quietly. So, if you try to use a different font and it does not seem to be working, it may be that the font in question is incompatible with Android, for whatever reason.

Also, you are probably best served by changing the case of your font filenames to be all lowercase, to match the naming convention used in the rest of your resources.

Also note that TrueType fonts can be rather pudgy, particularly if they support an extensive subset of the available Unicode characters. The Handmade Typewriter font used here runs over 70KB; the DejaVu free fonts can run upwards of 500KB apiece. Even compressed, these add bulk to your application, so be careful not to go overboard with custom fonts, or your application could take up too much room on your users’ phones.

CHAPTER 13

Embedding the WebKit Browser

Other GUI toolkits let you use HTML for presenting information, from limited HTML renderers (e.g., Java/Swing, wxWidgets) to embedding Internet Explorer into .NET applications. Android is much the same, in that you can embed the built-in Web browser as a widget in your own activities, for displaying HTML or full-fledged browsing. The Android browser is based on WebKit, the same engine that powers Apple’s Safari Web browser.

The Android browser is sufficiently complex that it gets its own Java package ( android.webkit), though using the WebView widget itself can be simple or powerful, based upon your requirements.

A Browser, Writ Small

For simple stuff, WebView is not significantly different than any other widget in Android — pop it into a layout, tell it what URL to navigate to via Java code, and you’re done.

For example, WebKit/Browser1is a simple layout with a WebView. You can find WebKit/Browser1along with all the code samples for this chapter in the Source Code area at http://apress.com.

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

/>

As with any other widget, you need to tell it how it should fill up the space in the layout (in this case, it fills all remaining space).

The Java code is equally simple:

packagecom.commonsware.android.webkit;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.webkit.WebView;

public classBrowserDemo1 extendsActivity {

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Beginning Android»

Представляем Вашему вниманию похожие книги на «Beginning Android» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Beginning Android»

Обсуждение, отзывы о книге «Beginning Android» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x