This page describes the different types of resources that you can externalize from your code and package with your application.
이 페이지는 여러분의 애플리케이션의 코드와 패키지로부터 외부화할 수 있는 다른 타입들의 리소스를 설명한다.
For more details on how to use resources in your application, please see the Resources and Internationalization documentation.
여러분의 애플리케이션에서 리소스를 사용하는 방법에 대한 보다 상세한 것에 대해서 앞서 언급된 “리소스와 국제화”를 보라.
All simple resource values can be expressed as a string, using various formats to unambiguously indicate the type of resource being created. For this reason, these values can be defined both as standard resources (under res/values/), as well as direct values supplied for mappings in styles and themes, and attributes in XML files such as layouts.
모든 간단한 리소스 값들은 하나의 문자열로 표시될 수 있다. 그것은 생성된 리소스의 타입을 명백하게 가리키기 위해 다양한 포맷을 사용하고 있다. 이런 이유로, 이들 값은 스타일과 테마의 매핑, 그리고 레이아웃과 같은 XML 파일의 애트리뷰트에 대해 제공된 직접적인 값 뿐만 아니라, 표준 리소스(res/values/ 아래에 있음) 두 가지 모두로 정의될 수 있다.
A color value specifies an RGB value with an alpha channel, which can
be used in various places such as specifying a solid color for a Drawable
or the color to use for text. A color value always begins with
a pound (#) character and then followed by the Alpha-Red-Green-Blue information
in one of the following formats:
컬러 값은 알파 채널을 가지는 RGB 값을 지정한다. 이것은 드로어블Drawable을 위한 솔리드 컬러solid color를 지정하거나 텍스트를 위해 사용할 컬러를 지정하는 것과 같이 다양한 장소에서 사용될 수 있다. 컬러 값은 항상 파운드(#) 문자로 시작하며, 그리고 나서 알파(Alpha)-빨강(Red)-초록(Green)-파랑(Blue) 정보가 이어진다. 이것은 다음과 같은 포맷 중 하나이다.
If you want to retrieve the color represented by a resource ID, you can call
the Resources.getColor() method.
만약 여러분이 리소스 ID에 대응되는 컬러를 얻고자 한다면, 여러분은 Resources.getColor() 메쏘드를 호출할 수 있다.
Source file format: XML file requiring a
<?xml version="1.0" encoding="utf-8"?> declaration, and
a root <resources> element containing one or more
<color> tags.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언을 요구하며, 그리고 루트 <resources> 엘리먼트는 하나 또는 그 이상의 <color> 태그를 포함한다.
Resource source file location: res/values/colors.xml (File name is arbitrary.)
리소스 소스 파일 위치: res/values/colors.xml (파일 이름은 상관없음)
Compiled resource datatype: Resource pointer to a Java int.
컴파일된 리소스 데이터 타입: Java int 에 대한 리소스 포인터
Resource reference name:
리소스 레퍼런스 이름:
R.color.some_name
@[package:]color/some_name (where some_name is the name of a specific color)
Syntax
구문
<color name=color_name>#color_value</color>
Example XML Declaration
예제 XML 선언(Example XML Declaration)
The following code declares two colors, the first fully opaque, and the second translucent.
다음의 코드는 두 개의 컬러를 선언한다. 첫 번째는 완전 불투명이고, 두 번째는 반투명이다.
<resources> <color name="opaque_red">#f00</color> <color name="translucent_red">#80ff0000</color> </resources>
Example Code Use
예제 코드 사용(Example Code Use)
Example Java code
예제 Java 코드:
// Retrieve a color value. int color = getResources.getColor(R.color.opaque_red);
Example XML code
예제 XML 코드:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlign="center"
android:textColor="@color/translucent_red"
android:text="Some Text"/>
Strings, with optional simple formatting, can be
stored and retrieved as resources. You can add formatting to your string by
using three standard HTML tags: <b>, <i>, and <u>. To
guarantee getting an unstyled string only (the raw text) call the
toString() method of the retrieved CharSequence object.
Methods that accept string resources should be able to process these styling
tags.
선택사항으로 간단한 포맷팅을 가지는 문자열은 리소스로써 저장되고 얻어질 수 있다. 여러분은 세 개의 표준 HTML 태그(<b>, <i>, 그리고 <u>)를 사용해서 여러분의 문자열에 포맷팅을 추가할 수 있다. 스타일이 적용되지 않은 문자열(원시 텍스트)만을 얻는 것을 보증하기 위해서는, 얻어 온 CharSequence 오브젝트의 toString() 메쏘드를 호출하라. 문자열 리소스를 수용하는 메쏘드는 이러한 스타일링 태그를 처리할 수 있어야 한다.
If you want to retrieve the String represented by a resource ID, you can call the Context.getString() method.
만약 여러분이 리소스 ID에 대응되는 문자열을 얻고자 한다면, 여러분은 Context.getString() 메쏘드를 호출할 수 있다.
Note: If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes:
Note: 여러분이 만약 여러분의 문자열에서 어퍼스트로피(‘) 또는 따옴표를 사용한다면, 여러분은 그것을 이스케이프escape하거나 또는 다른 종류의 따옴표로 전체 문자열을 감싸야 한다. (역주: 만약 문자열에 작은 따옴표가 있다면 큰 따옴표로 전체 문자열을 감싸고, 큰 따옴표가 있다면 작은 따옴표로 전체 문자열을 감싸야 한다.)
<string name="good_example">"This'll work"</string> <string name="good_example_2">This\'ll also work</string> <string name="bad_example">This won't work!</string> <string name="bad_example_2">XML encodings won't work either!</string>
Source file format: XML file requiring a <?xml version="1.0" encoding="utf-8"?> declaration, and a root <resources> element containing one or more <string> tags.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언을 요구하며, 루트 <resources> 엘리먼트는 하나 또는 그 이상의 <string> 태그를 포함한다.
Resource source file location: res/values/strings.xml (File name is arbitrary.)
리소스 소스 파일 위치: res/values/strings.xml (파일 이름은 상관없음)
Compiled resource datatype: Resource pointer to a Java CharSequence.
컴파일된 리소스 데이터 타입: Java CharSequence 에 대한 리소스 포인터
Resource reference name:
리소스 레퍼런스 이름:
R.string.some_name
@[package:]string/some_name (where some_name is the name of a specific string)
Syntax
구문
<string name=string_name>string_value</string>
Example XML Declaration
예제 XML 선언(Example XML Declaration)
The following declares two strings: the first simple text with no
formatting (resulting in a CharSequence that is simply a String object) the second includes formatting information in the string (resulting
in a CharSequence that is a complex data structure). If you are using the custom editor for string files in Eclipse, the HTML formatting tags will automatically be escaped and you will need to use Context.getString() and fromHtml(String) to retreive the resource and then convert it to formatted text.
아래의 XML 예제는 두 개의 문자열을 선언한다. 첫 번째는 포맷팅 없는 간단한 텍스트(간단한 스트링 오브젝트인 CharSequence)이며, 두 번째는 문자열에 포맷팅 정보(복잡한 데이터 구조인 CharSequence)를 포함한다. 만약 여러분이 이클립스에서 문자열 파일에 대한 커스텀 에디터를 사용한다면, HTML 포맷팅 태그는 자동으로 사라질 것이며, 여러분은 리소스를 얻기 위해 Context.getString()과 fromHtml(String)를 사용할 필요가 있고, 그런 다음에 그것을 포맷된 텍스트로 변환해야 한다. (역주 : getString()대신 getText()를 사용하여야 함.)
<resources> <string name="simple_welcome_message">Welcome!</string> <string name="styled_welcome_message">We are <b><i>so</i></b> glad to see you.</string> </resources>
Example Code Use
예제 코드 사용(Example Code Use)
Example Java code
예제 Java 코드:
// Assign a styled string resource to a TextView // on the current screen. CharSequence str = getString(R.string.styled_welcome_message); TextView tv = (TextView)findViewByID(R.id.text); tv.setText(str);
Example XML code
예제 XML 코드:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlign="center"
android:text="@string/simple_welcome_message"/>
Sometimes you may want to create a styled text resource that is also used as a format string. This cannot be done directly because there is no way of passing the styled text as the format string argument of String.format() without stripping out the style information. The workaround is to store the style tags as escaped HTML tags, and then convert the escaped HTML string into a styled text after formatting has taken place.
가끔 여러분은 포맷 문자열로써도 사용될 수 있는 스타일을 가진 텍스트 리소스를 생성하길 원할 수 있다. 이것은 직접적으로 될 수는 없다. 왜냐하면 스타일 정보를 제거하지 않고 String.format()의 포맷 문자열 아큐먼트로써 스타일을 가진 텍스트를 전달하는 방법이 없기 때문이다. 차선책은 이스케이프된escaped HTML 태그로써 스타일 태그를 저장하는 것이다. 그리고 나서 포맷팅을 한 후에 이스케이프된escaped HTML 문자열을 스타일을 가진 텍스트로 변환하라.
To use styled text as a format string, do the following.
포맷 문자열로써 스타일이 있는 텍스트를 사용하기 위해서는 다음을 수행하라.
<resources> <string name="search_results_resultsTextFormat">%1$d results for <b>&quot;%2$s&quot;</b></string> </resources>
In this example the format string has two arguments: %1$d is a decimal number, %2$s is a string.
htmlEncode(String) method will do this:
String escapedTitle = TextUtil.htmlEncode(title);
fromHtml(String) to convert the HTML text into styled text:
String resultsTextFormat = getContext().getResources().getString(R.string.search_results_resultsTextFormat); String resultsText = String.format(resultsTextFormat, count, escapedTitle); CharSequence styledResults = Html.fromHtml(resultsText);
<resources> <string name="search_results_resultsTextFormat">%1$d results for <b>&quot;%2$s&quot;</b></string> </resources>
이 예제에서 포맷 문자열은 두 개의 아규먼트를 가진다. %1$d는 숫자, %2$s는 문자열임.
String escapedTitle = TextUtil.htmlEncode(title);
String resultsTextFormat = getContext().getResources().getString(R.string.search_results_resultsTextFormat); String resultsText = String.format(resultsTextFormat, count, escapedTitle); CharSequence styledResults = Html.fromHtml(resultsText);
You can create common dimensions to use for various screen elements by defining dimension values in XML. A dimension resource is a number followed by a unit of measurement. For example: 10px, 2in, 5sp. Here are the units of measurement supported by Android:
크기 값(Dimension Values)여러분은 XML로 크기dimension 값을 정의함으로써, 다양한 스크린 엘리먼트를 위해 사용할 일반적인 크기를 생성할 수 있다. 크기dimension 리소스는 측정 단위가 뒤에 붙는 하나의 숫자이다. 예를 들어 10px, 2in, 5sp가 그것이다. 여기에 안드로이드에 의해 지원되는 측정 단위가 있다.
Dimension values are not normally used as raw resources, but rather as attribute values in XML files. You can, however, create plain resources containing this data type.
크기dimension 값은 일반적으로 원시 리소스로서 사용되기 보다는 오히려 XML 파일의 애트리뷰트 값으로써 사용된다. 하지만 여러분은 이 데이터 타입을 포함하는 일반적인 리소스를 생성할 수 있다.
Source file format: XML file requiring a <?xml
version="1.0" encoding="utf-8"?> declaration, and a root
<resources> element containing one or more
<dimen> tags.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언을 요구하며, 루트 <resources> 엘리먼트는 하나 또는 그 이상의 <dimen> 태그를 포함한다.
Resource source file location: res/values/dimens.xml (File
name is arbitrary, but standard practice is to put all dimensions in one file
devoted to dimensions.)
리소스 소스 파일 위치: res/values/dimens.xml (파일 이름은 상관없음. 표준 사례는 치수를 다루는 하나의 파일에 모든 치수들을 넣는 것이다).
Compiled resource datatype: Resource pointer to a dimension.
컴파일된 리소스 데이터타입: dimension에 대한 리소스 포인터.
Resource reference name:
리소스 레퍼런스 이름:
R.dimen.some_name
@[package:]dimen/some_name (where some_name is the name of a specific <dimen> element)
Syntax
구문
<dimen name=dimen_name>dimen_value</dimen>
Example XML Declaration
예제 XML 선언(Example XML Declaration)
The following code declares several dimension values.
다음의 코드는 몇가지 치수 값을 선언한다.
<resources>
<dimen name="one_pixel">1px</dimen>
<dimen name="double_density">2dp</dimen>
<dimen name="sixteen_sp">16sp</dimen>
</resources>
Example Code Use
예제 코드 사용(Example Code Use)
Example Java code:
예제 Java 코드:
float dimen = Resources.getDimen(R.dimen.one_pixel);
Example XML code:
예제 XML 코드:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/sixteen_sp"/>
A Drawable is a type of resource that
you retrieve with Resources.getDrawable() and use to draw to the screen. There are a
number of drawable resources that can be created.
드로어블Drawable은 여러분이 Resources.getDrawable()을 사용해서 얻어와서 스크린에 그리기 위해 사용하는 리소스의 한 타입이다. 생성될 수 있는 다수의 드로어블drawable 리소스들이 있다.
Android supports bitmap resource files in a few different formats: png (preferred), jpg (acceptable), gif (discouraged). The bitmap file itself is compiled and referenced by the file name without the extension (so res/drawable/my_picture.png would be referenced as R.drawable.my_picture).
안드로이드는 다소 다른 포맷 - png(선호되는), jpg(수용가능한), gif(좋지않은) - 의 비트맵 리소스 파일을 지원한다. 비트맵 파일 그 자체는 컴파일되어 확장자 없는 파일명으로 레퍼런스된다(그러므로 res/drawable/my_picture.png는 R.drawable.my_picture 로써 레퍼런스될 것이다).
Source file formats: png (preferred), jpg (acceptable), gif (discouraged). One resource per file.
소스 파일 포맷: png(선호되는), jpg(수용가능한), gif(좋지않은). 파일당 하나의 리소스.
Resource file location: res/drawable/some_file.png
리소스 파일 위치: res/drawable/some_file.png
Compiled resource datatype: Resource pointer to a BitmapDrawable.
컴파일된 리소스 데이터 타입: BitmapDrawable에 대한 리소스 포인터.
Resource reference name:
리소스 레퍼런스 이름:
R.drawable.some_file
@[package:]drawable/some_file
For more discussion and examples using drawable resources, see the discussion in 2D Graphics.
드로어블Drawable 리소스 사용에 대한 더 많은 논의와 예제는, 10장. “그래픽”의 “2차원 그래픽”을 보라.
You can create a PaintDrawable object that is a rectangle of color,
with optionally rounded corners. This element can be defined in any of the
files inside res/values/.
여러분은 선택사항으로 둥근 모서리를 가지는 직사각형의 컬러 PaintDrawable 오브젝트를 만들 수 있다. 이 엘리먼트는 res/values/ 내의 어떤 파일에서나 정의될 수 있다.
Source file format: XML file requiring a <?xml
version="1.0" encoding="utf-8"?> declaration, and a root
<resources> element containing one or more
<drawable> tags.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언을 요구하며, 루트 <resources> 엘리먼트는 하나 또는 그 이상의 <drawable> 태그를 포함한다.
Resource source file location: res/values/colors.xml (File name is arbitrary, but standard practice is to put the PaintDrawable
items in the file along with the numeric color values.)
리소스 소스 파일 위치: res/values/colors.xml (파일이름은 상관없음. 표준 사례는 파일에 숫자 컬러 값과 PaintDrawable 아이템을 넣는 것이다)
Compiled resource datatype: Resource pointer to a PaintDrawable.
컴파일된 리소스 데이터타입: PaintDrawable에 대한 리소스 포인터.
Resource reference name:
리소스 레퍼런스 이름:
R.drawable.some_name
@[package:]drawable/some_name (where some_name is the name of a specific resource)
Syntax
구문
<drawable name=color_name>color_value</drawable>
Example XML Declaration
예제 XML 선언(Example XML Declaration)
The following code declares several color drawables.
다음 코드는 몇가지 컬러 드로어블(drawables)을 선언한다.
<resources>
<drawable name="solid_red">#f00</drawable>
<drawable name="solid_blue">#0000ff</drawable>
<drawable name="solid_green">#f0f0</drawable>
</resources>
Example Code Use
예제 코드 사용(Example Code Use)
Example Java code
예제 Java 코드:
// Assign a PaintDrawable as the background to // a TextView on the current screen. Drawable redDrawable = Resources.getDrawable(R.drawable.solid_red); TextView tv = (TextView)findViewByID(R.id.text); tv.setBackground(redDrawable);
Example XML code
예제 XML 코드:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlign="center"
android:background="@drawable/solid_red"/>
Android supports a stretchable bitmap image, called a
NinePatch graphic. This is a PNG image in which
you define stretchable sections that Android will resize to fit the object
at display time to accommodate variable sized sections, such as text strings.
You typically assign this resource to the View's background. An example use
of a stretchable image is the button backgrounds that Android uses; buttons
must stretch to accommodate strings of various lengths.
안드로이드는 나인패치NinePatch 그래픽이라 불리는 확대가능한stretchable 비트맵 이미지를 지원한다. 이것은 PNG 이미지이며, 여러분은 그 안에 확대가능한stretchable 섹션을 정의하며, 안드로이드는 디스플레이 시점에 이 오브젝트를 텍스트 문자열과 같은 가변적 크기 섹션을 수용할 수 있도록 크기를 변경할 것이다. 여러분은 일반적으로 뷰의 백그라운드에 이 리소스를 할당한다. 확대가능한Stretchable 이미지의 사용 예제는 안드로이드가 사용하는 버튼Button 백그라운드이다. 버튼은 다양한 길이의 문자열을 수용하기 위해 확대되어야 한다.
Source file format: PNG one resource per file
소스 파일 포맷: PNG ? 파일 별로 하나의 리소스
Resource source file location: res/drawable/some_name.9.png (Filename must end in .9.png)
리소스 소스 파일 위치: res/drawable/some_name.9.png (.9.png 로 끝나야 함.)
Compiled resource datatype: Resource pointer to a NinePatchDrawable.
컴파일된 리소스 데이터타입: NinePatchDrawable에 대한 리소스 포인터
Resource reference name:
리소스 레퍼런스 이름:
R.drawable.some_file
@[package:]drawable.some_file
For more information and examples using NinePatch drawables, see the discussion in 2D Graphics.
나인패치NinePatch 드로어블drawables을 사용하는 더 많은 정보와 예제는, 10장. “그래픽”의 “2차원 그래픽”을 보라.
Android can perform simple animation on a graphic, or a series of graphics. These include rotations, fading, moving, and stretching.
안드로이드는 그래픽 또는 그래픽 시리즈에 간단한 애니메이션을 수행할 수 있다. 이것들은 회전rotations과 페이딩fading, 움직임moving, 확대stretching를 포함한다.
Source file format: XML file, one resource per file, one root tag with no <?xml> declaration
소스 파일 포맷: XML 파일, 파일 별로 하나의 리소스, <?xml> 선언을 갖지 않는 하나의 루트 태크
Resource file location: res/anim/some_file.xml
리소스 파일 위치: res/anim/some_file.xml
Compiled resource datatype: Resource pointer to an Animation.
컴파일된 리소스 데이터타입: Animation에 대한 리소스 포인터
Resource reference name:
리소스 레퍼런스 이름:
R.anim.some_file
@[package:]anim/some_file
Syntax
구 문
The file must have a single root element: this will be either a single <alpha>, <scale>, <translate>, <rotate>, interpolator element, or <set> element that holds groups of these elements (which may include another <set>). By default, all elements are applied simultaneously. To have them occur sequentially, you must specify the startOffset attribute.
파일은 하나의 루트 엘리먼트를 가져야 한다. 이것은 하나의 <alpha>, <scale>, <translate>, <rotate>, interpolator 엘리먼트, 또는 이러한 엘리먼트들의 그룹을 보유하는 <set> 엘리먼트가 될 수 있다(<set>은 또 다른 <set>을 포함할 수도 있다). 디폴트로, 모든 엘리먼트들은 동시에 적용된다. 그것들이 순차적으로 일어나게 하기 위해서는, 여러분이 startOffset 애트리뷰트를 지정해야 한다.
<set android:shareInterpolator=boolean> // Only required if multiple tags are used.
<alpha android:fromAlpha=float
android:toAlpha=float > |
<scale android:fromXScale=float
android:toXScale=float
android:fromYScale=float
android:toYScale=float
android:pivotX=string
android:pivotY=string > |
<translate android:fromX=string
android:toX=string
android:fromY=string
android:toY=string > |
<rotate android:fromDegrees=float
android:toDegrees=float
android:pivotX=string
android:pivotY=string > |
<interpolator tag>
<set>
</set>
Elements and Attributes
엘리먼트와 애트리뷰트(Elements and Attributes)
AnimationSet.
You can include as many child elements of the same or different types as you like.
Supports the following attribute:
AlphaAnimation.
Supports the following attributes:
ScaleAnimation.
You can specify what is the center point of the image (the pinned center), from which it grows outward (or inward), by specifying pivotX and pivotY. So, for example, if these were 0, 0 (top left corner), all growth would be down and to the right. scale supports the following attributes:
TranslateAnimation.
Supports the following attributes in any of the following three formats: values from -100 to 100, ending with "%", indicating a percentage relative to itself; values from -100 to 100, ending in "%p", indicating a percentage relative to its parent; a float with no suffix, indicating an absolute value.
RotateAnimation.
Supports the following attributes:
R.styleable. Examples include <CycleInterpolator>, <EaseInInterpolator>, and <EaseOutInterpolator>. These objects define a velocity curve that describes how quickly a visual action takes place on a timeline (fast at first and slow later, slow at first and gradually faster, and so on).
In addition to the attributes defined for each element above, the elements
<alpha>, <scale>, <translate>,
<rotate>, and <set> all support the following attributes (inherited
from the Animation class):
위의 각각의 엘리먼트에 대해 정의된 애트리뷰트에 추가적으로, 엘리먼트 <alpha>, <scale>, <translate>, <rotate>, 그리고 <set> 모두는 (Animation 클래스로부터 상속된) 다음과 같은 애트리뷰트들을 지원한다.
durationstartOffsetfillBeforefillAfterrepeatCountrepeatModezAdjustmentinterpolatorR.anim. To specify these, use the syntax @android:anim/interpolatorName.
For more discussion and animation code samples, see the discussion in the 2D Graphics document.
더 많은 논의와 애니메이션 코드 샘플을 위해서는 10장. “그래픽”의 “2차원 그래픽”을 보라.
Application menus (Options Menu, Context Menu, or Sub Menu) can be defined as
XML resources and inflated by your application using MenuInflater.
애플리케이션 메뉴(옵션 메뉴, 컨텍스트 메뉴, 또는 서브 메뉴)는 XML 리소스로써 정의될 수 있으며, 여러분의 애플리케이션에 의해 MenuInflater를 사용해서 인플레이트inflate 된다.
Source file format: XML file, one resource per file, one root tag,
<?xml> declaration not required.
소스 파일 포맷: XML 파일, 파일 별로 하나의 리소스, 하나의 루트 태그, <?xml> 선언이 요구되지 않음.
Resource file location: res/menu/some_file.xml
리소스 파일 위치: res/menu/some_file.xml
Compiled resource datatype: Resource pointer to a Menu (or subclass) resource.
컴파일된 리소스 데이터타입: Menu (또는 서브 클래스) 리소스에 대한 리소스 포인터
Resource reference name:
리소스 레퍼런스 이름:
R.menu.some_fileThe file must have a single root element: a <menu> element. In all,
there are three valid elements: <menu>, <group> and <item>. The
<item> and <group> elements must be the children of a <menu>, but <item>
elements can also be the children of a <group>, and another <menu> element may be the child
of an <item> (to create a Sub Menu).
그 파일은 하나의 루트 엘리먼트인 <menu> 엘리먼트를 가져야 한다. 모두 합쳐 세 개의 유효한 엘리먼트가 있다. <menu>, <group>, 그리고 <item>이 그것이다. <item>과 <group> 엘리먼트는 <menu>의 자식들children이 되어야 한다. 그러나 <item> 엘리먼트 또한 <group>의 자식들children이 될 수 있으며, (서브 메뉴를 생성하기 위해) 또 다른 <menu> 엘리먼트가 <item>의 자식child가 될 수도 있다.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/example_item
android:title="Example Item"
android:icon="@drawable/example_item_icon" />
<group android:id="@+id/example_group">
<item android:id="@+id/example_item2
android:title="Example Item 2"
android:icon="@drawable/example_item2_icon" />
</group>
<item android:id="@+id/example_submenu
android:title="Example Sub Menu" >
<menu>
<item android:id="@+id/example_submenu_item
android:title="Example Sub Menu Item" />
</menu>
</item>
</menu>
All attributes must be defined with the android namespace (e.g., android:icon="@drawable/icon").
모든 애트리뷰트는 android 네임스페이스(예를 들어 android:icon=”@drawable/icon)를 가지고 정의되어야 한다.
<item> and <group> nodes. No attributes.<item> elements. Valid attributes:
<menu> element (for a Sub Menu). Valid attributes:
For more discussion on how to create menus in XML and inflate them in your application, read Creating Menus.
XML로 메뉴를 만드는 방법과 그것들을 여러분의 애플리케이션에서 인플레이트inflate 하는 방법에 대한 더 많은 논의는 “메뉴 생성하기” 섹션을 읽어라.
Android lets you specify screen layouts using XML elements inside an XML
file, similar to designing screen layout for a webpage in an HTML file. Each
file contains a whole screen or a part of a screen, and is compiled into a
View resource that can be passed in to
Activity.setContentView or used as a
reference by other layout resource elements. Files are saved in the
res/layout/ folder of your project, and compiled by the Android resource
compiler, aapt.
안드로이드는 여러분이 HTML 파일로 웹 페이지에 대한 스크린 레이아웃을 디자인하는 것과 유사하게 XML 파일 내의 XML 엘리먼트를 사용하여 스크린 레이아웃을 지정하는 것을 가능하게 한다. 각각의 파일은 전체 스크린 또는 스크린의 일부를 포함하며, 그리고 뷰 리소스로 컴파일된다. 이것은 Activity.setContentView()에 전달되거나 또는 그 밖의 레이아웃 리소스 엘리먼트에 의해 레퍼런스로 사용될 수 있다. 파일은 여러분 프로젝트의 res/layout 폴더에 저장되며, 안드로이드 리소스 컴파일러인 aapt에 의해 컴파일된다.
Every layout XML file must evaluate to a single root element. First we'll describe how to use the standard XML tags understood by Android as it is shipped, and then we'll give a little information on how you can define your own custom XML elements for custom View objects.
모든 레이아웃 XML 파일은 하나의 루트 엘리먼트를 가져야 한다. 먼저 우리는 그것이 XML에 적재된 대로, 안드로이드에 의해 이해되는 표준 XML 태그를 사용하는 방법을 설명할 것이고, 그리고 나서 커스텀 뷰 오브젝트를 위한 여러분 자신의 커스텀 XML 엘리먼트 정의 방법에 대한 약간의 정보를 제공할 것이다.
The root element must have the Android namespace "http://schemas.android.com/apk/res/android" defined in the root element.
루트 엘리먼트는 루트 엘리먼트에 정의된 “http://schemas.android.com/apk/res/android”, Android 네임스페이스를 가져야 한다.
For a complete discussion on creating layouts, see the User Interface topic.
레이아웃을 생성하는 것에 대한 완전한 논의에 대해서는 3장. “사용자 인터페이스” 를 보라.
Source file format: XML file
requiring a <?xml version="1.0" encoding="utf-8"?>
declaration, and a root element of one of the supported XML layout elements.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언과 그리고 지원되는 XML 레이아웃 엘리먼트 중 하나가 루트 엘리먼트가 되어야 한다.
Resource file location: res/layout/some_file.xml.
리소스 파일 위치: res/layout/some_file.xml
Compiled resource datatype: Resource pointer to a View (or subclass) resource.
컴파일된 리소스 데이터타입: View (또는 서브클래스) 리소스에 대한 리소스 포인터.
Resource reference name:
리소스 레퍼런스 이름:
R.layout.some_file
@[package:]layout/some_file
Syntax
구 문
<ViewGroupClass xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/string_name" (attributes)>
<widget or other nested ViewGroupClass>+
<requestFocus/>(0 or 1 per layout file, assigned to any element)
</ViewGroupClass>
The file must have a single root element. This can be a ViewGroup class that contains other elements, or a widget (or custom item) if it's only one object. By default, you can use any (case-sensitive) Android widget or ViewGroup class name as an element. These elements support attributes that apply to the underlying class, but the naming is not as clear. How to discover what attributes are supported for what tags is discussed below. You should not assume that any nesting is valid (for example you cannot enclose <TextView> elements inside a <ListLayout>).
If a class derives from another class, the XML element inherits all the attributes from the element that it "derives" from. So, for example, <EditText> is the corresponding XML element for the EditText class. It exposes its own unique attributes (EditText_numeric), as well as all attributes supported by <TextView> and <View>. For the id attribute of a tag in XML, you should use a special syntax: "@+id/somestringvalue". The "@+" syntax creates a resource number in the R.id class, if one doesn't exist, or uses it, if it does exist. When declaring an ID value for an XML tag, use this syntax. Example: <TextView android:id="@+id/nameTextbox"/>, and refer to it this way in Java: findViewById(R.id.nameTextbox). All elements support the following values:
xmlns:android="http://schemas.android.com/apk/res/android" - Required for the root element only.
그 파일은 하나의 루트 엘리먼트를 가져야 한다. 이것은 다른 엘리먼트를 포함하는 뷰그룹 클래스가 될 수 있으며, 또한 만약 그것이 오직 하나의 오브젝트라면 위젯 (또는 커스텀 아이템)이 될 수도 있다. 디폴트로, 여러분은 엘리먼트로 어떤 (대소문자를 구분하는) 안드로이드 위젯이나 뷰그룹 클래스 이름을 사용할 수 있다. 이러한 엘리먼트들은 그 아래에 놓인(역주: 대응대는) 클래스에 적용하는 애트리뷰트를 지원한다. 하지만 그 네이밍naming은 분명하지 않다. 어떤 태그에서 어떤 어떤 애트리뷰트가 지원되는가를 찾는 방법이 아래에 설명되었다. 여러분은 어떤 네스팅nesting이든 유효하다고 가정해서는 안된다(예를 들어 여러분은 <ListLayout> 안에 <TextView> 엘리먼트를 포함할 수 없다).
만약 클래스가 다른 클래스로부터 파생된다면, XML 엘리먼트는 그것이 파생된 그 엘리먼트로 부터 모든 애트리뷰트를 상속한다. 그러므로 예를 들어 <EditText>는 EditText 클래스에 대응되는 XML 엘리먼트이다. 그것은 <TextView>와 <View>에 의해 지원되는 모든 애트리뷰트 뿐만 아니라, 그것 자신의 고유한 애트리뷰트(EditText_numeric)를 제시한다. XML 안에 있는 태그의 id 애트리뷰트에 대해, 여러분은 특별한 구문(“@+id/somestringvalue”)을 사용해야 한다. “@+” 구문은 만약 R.id 클래스에 리소스 숫자가 존재하지 않는다면 그것을 생성하며, 만약 그것이 존재한다면 그것을 사용한다. XML 태그에 대한 ID 값를 선언할 때, 이 구문을 사용하라. 예제: <TextView id= “@+id/nameTextbox”/>, 그리고 Java에서 이러한 방법, findViewById(R.id.nameTextbox)로 그것을 레퍼런스하라. 모든 엘리먼트는 다음의 값들을 지원한다.
What Attributes Are Supported for What Elements?
어떤 엘리먼트에 대해 어떤 애트리뷰트가 지원되는가?
Android uses the LayoutInflater class at run time to load an XML layout resource and translate it into visual elements. By default, all widget class names are supported directly as tags, but a full list of supported tags and attributes is listed in the R.styleable reference page. However, the attribute names are somewhat obscure. If an underscore appears in the name, this indicates that it is an attribute typically of the element before the underscore. So, for example, EditText_autoText means that the <EditText> tag supports an attribute autoText. When you actually use the attribute in that element, use only the portion after the last underscore, and prefix the attribute with the prefix "android:". So, for example, if R.styleable lists the following values:
안드로이드는 런타임에서 XML 레이아웃 리소스를 로드해서 그것을 비쥬얼 엘리먼트로 변경하기 위해 LayoutInflater 클래스를 사용한다. 디폴트로, 모든 위젯 클래스 이름은 태그로 직접적으로 사용된다. 더불어 지원되는 모든 태그와 애트리뷰트 리스트는 R.styleable 레퍼런스 페이지에 리스트된다. 하지만 애트리뷰트 이름은 다소 분명하지 않다. 만약 그 이름에 밑줄(_)이 나타나면, 이것은 그것이 애트리뷰트라는 것을 가리킨다(일반적으로 밑줄 앞이 엘리먼트의 이름이다). 그러므로 예를 들어 EditText_autoText는 <EditText> 태그가 애트리뷰트로 autoText를 지원한다는 것을 의미한다. 여러분이 실제로 그 엘리먼트에 있는 애트리뷰트를 사용할 때, 마지막 밑줄 이후의 영역만을 사용하라. 그리고 그 애트리뷰트에 접두어 “android:”를 붙여라. 그러므로 예를 들어 만약 R.styleable이 다음과 같은 값들을 리스트한다면,
TextView
TextView_lines
TextView_maxlines
You could create an element like this:
여러분은 다음과 같은 하나의 엘리먼트를 생성할 수 있다.
<TextView android:lines="10" android:maxlines="20"/>
This would create a TextView object and set its lines and maxlines properties.
이것은 TextView 오브젝트를 만들 것이고, 그것의 lines과 maxlines 속성들을 설정할 것이다.
Attributes come from three sources:
애트리뷰트는 세 개의 소스로부터 온다.
TextView supports TextView_text, as discussed above.
<TextView> element supports all the attributes that the <View> element exposes a long list, including View_paddingBottom and View_scrollbars. These too are used without the class name: <TextView android:paddingBottom="20" android:scrollbars="horizontal" />.
ViewGroup.LayoutParams subclass. All View objects support a LayoutParams member (see Declaring Layout). To set properties on an element's LayoutParams member, the attribute to use is "android:layout_layoutParamsProperty". For example: android:layout_gravity for an object wrapped by a <LinearLayout> element. Remember that each LayoutParams subclass also supports inherited attributes. Attributes exposed by each subclass are given in the format someLayoutParamsSubclass_Layout_layout_someproperty. This defines an attribute "android:layout_someproperty". Here is an example of how Android documentation lists the properties of the LinearLayout.LayoutParams class:
gravity attribute
height attribute
weight attribute
width attribute
Here is an example that sets some of these values on a few objects, including direct attributes, inherited attributes, and LayoutParams attributes:
여기에 직접적인 애트리뷰트, 상속된 애트리뷰트, 그리고 LayoutParams 애트리뷰트를 포함하는 몇 개의 오브젝트에, 이러한 값들 중 몇 개를 설정하는 예제가 있다
<?xml version="1.0" encoding="utf-8"?>
<!-- res/main_screen.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" // The object's own orientation property
android:padding="4" // Inherited View property
android:gravity="center" // The object's own property
android:layout_width="fill_parent" // Parent object's LinearLayout.LayoutParams.width
android:layout_height="fill_parent"> // Parent object's LinearLayout.LayoutParams.height
<TextView android:layout_width="fill_parent" // TextView.LayoutParams.width
android:layout_height="wrap_content" // TextView.LayoutParams.height
android:layout_weight="0" // TextView.LayoutParams.weight
android:paddingBottom="4" // TextView.paddingBottom
android:text="@string/redirect_getter"/> // TextView.text
<EditText android:id="@+id/text"
android:layout_width="fill_parent" // EditText.LayoutParams.width
android:layout_height="wrap_content" // EditText.LayoutParams.height
android:layout_weight="0" // EditText.LinearLayoutParams.weight
android:paddingBottom="4"> // EditText.paddingBottom
<requestFocus />
</EditText>
<Button android:id="@+id/apply"
android:layout_width="wrap_content" // Button.LayoutParams.width
android:layout_height="wrap_content" // Button.LayoutParams.height
android:text="@string/apply" /> // TextView.text
</LinearLayout>
Example Code Use
예제 코드 사용(Example Code Use)
The most common use is to load the XML file (located at res/main_screen.xml) and use it as the current screen, as shown here with the preceding file:
가장 일반적인 사용은 XML 파일(res/layout/main_screen.xml)을 로드하고, 선행하는 파일을 가지고 아래에 보여지듯이 현재 스크린으로 그것을 사용하는 것이다.
setContentView(R.layout.main_screen);
However, layout elements can also represent repeating elements used as templates.
하지만 레이아웃 엘리먼트는 템플릿처럼 사용되는 반복하는 엘리먼트를 또한 표현할 수 있다.
Also see User Interface for more information on layouts.
더불어, 레이아웃에 대한 더 많은 정보는 3.장 “사용자 인터페이스”를 보라.
You can define custom elements to use in layout resources. These custom elements can then be used the same as any Android layout elements: that is, you can use them and specify their attributes in other resources. The ApiDemos sample application has an example of creating a custom layout XML tag, LabelView. To create a custom element, you will need the following files:
여러분은 레이아웃 리소스에서 사용하기 위한 커스텀 엘리먼트를 정의할 수 있다. 그리고 나서 이러한 커스텀 엘리먼트는 임의의 안드로이드 레이아웃 엘리먼트처럼 동일하게 사용될 수 있다. 즉, 여러분은 다른 리소스에서 그것을 사용하고 그것의 애트리뷰트를 지정할 수 있다. ApiDemos 샘플 애플리케이션에는 LabelView라는 커스텀 레이아웃 XML 태그를 생성하는 예제가 있다. 커스텀 엘리먼트를 만들기 위해서, 여러분은 다음에 오는 파일들을 필요로 할 것이다.
View or a subclass. See LabelView.java in ApiDemos.
<declare-styleable name=your_java_class_name>. See res/values/attrs.xml in ApiDemos.
Source file format: XML file without an <?xml> declaration, and a <resources> root element containing one or more custom element tags.
소스 파일 포맷: <?xml> 선언이 없는 XML 파일, 그리고 <resources> 루트 엘리먼트는 하나 또는 그 이상의 커스텀 엘리먼트 태그를 포함한다.
Resource file location: res/values/attrs.xml (File name is arbitrary.)
리소스 파일 위치: res/values/attrs.xml (파일 이름은 상관없음)
Compiled resource datatype: Resource pointer to a View (or subclass) resource.
컴파일된 리소스 데이터타입: 뷰(또는 서브클래스) 리소스에 대한 리소스 포인터.
Resource reference name: R.styleable.some_file (Java).
리소스 레퍼런스 이름: R.styleable.some_file (Java)
A style is one or more attributes applied to a single element (for example, 10 point red Arial font, applied to a TextView). A style is applied as an attribute to an element in a layout XML file.
스타일은 하나의 엘리먼트에 적용되는 하나 또는 그 이상의 애트리뷰트들이다. (예를 들어 10 point red Arial 폰트가 TextView에 적용된) 스타일은 레이아웃 XML 파일 내의 하나의 엘리먼트에 하나의 애트리뷰트로서 적용된다.
A theme is one or more attributes applied to a whole screen for example, you might apply the stock Android Theme.dialog theme to an activity designed to be a floating dialog box. A theme is assigned as an attribute to an Activity in the manifest file.
테마는 전체 스크린에 적용되는 하나 또는 그 이상의 애트리뷰트이다 - 예를 들어 여러분은 액티비티가 스크린에 떠 있는floating 다이얼로그 박스가 되도록 디자인하기 위해, 안드로이드 Theme.dialog 테마를 스탁stock에 적용할 지 모른다. 테마는 매니페스트 파일에 있는 activity의 애트리뷰트로 지정된다.(역주: 테마매니페스트의 application의 애트리뷰트에도 지정할 수 있다.)
Both styles and themes are defined in a <style> block containing one or more string or numerical values (typically color values), or references to other resources (drawables and so on). These elements support inheritance, so you could have MyBaseTheme, MyBaseTheme.Fancy, MyBaseTheme.Small, and so on.
스타일과 테마 둘 다, 하나 또는 그 이상의 문자열 또는 숫자 값(일반적으로 컬러 값), 또는 다른 리소스들(드로어블(drawable) 등등)에 대한 레퍼런스를 포함하는 <style> 블락으로 정의된다. 이 엘리먼트는 상속을 지원한다. 그러므로 여러분은 MyBaseTheme, MyBaseTheme.Fancy, MyBaseTheme.Small 등등을 가질 수 있다.
For a complete discussion on styles and themes, read Applying Styles and Themes.
스타일과 테마에 대한 완전한 논의에 대해서는, “스타일과 테마 적용하기” 섹션을 읽어라.
Source file format: XML file requiring a <?xml version="1.0" encoding="utf-8"?> declaration, and a root <resources> element containing one or more <style> tags.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언을 요구하며, 루트 <resources> 엘리먼트는 하나 또는 그 이상의 <style> 태그를 포함한다.
Resource source file location: res/values/styles.xml (File name is arbitrary, but standard practice is to put all styles into a file named styles.xml.)
리소스 소스 파일 위치: res/values/styles.xml (파일 이름은 상관없으나, 표준 사례는 styles.xml 이라 불리는 하나의 파일에 모든 스타일을 넣은 것이다.)
Compiled resource datatype: Resource pointer to a Java CharSequence.
컴파일된 리소스 데이터타입: Java CharSequence 에 대한 리소스 포인터.
Resource reference name:
리소스 레퍼런스 이름:
R.style.styleID for the whole style, R.style.styleID.itemID for an individual setting
@[package:]style/styleID for a whole style, @[package:]style/styleID/itemID for an individual item. Note: to refer to a value in the currently applied theme, use "?" instead of "@" as described below (XML).
Syntax
구 문
<style name=string [parent=string] > <item name=string>Hex value | string value | reference</item>+ </style>
android:Theme for the base Android theme, or MyTheme for a theme defined in your package).
For examples of how to declare and apply styles and themes, read Applying Styles and Themes.
스타일과 테마를 선언하고, 적용하는 방법에 대한 예제에 대해서는, “스타일과 테마 적용하기” 섹션을 읽어라.
To make search appear to the user as a seamless system-wide feature, the Android framework offers APIs that let applications control how they are searched. Applications can customize how search is invoked, how the search dialog looks, and what type of search results are available, including suggestions that are shown as the user types.
시스템 전체의 끊김없는 기능으로써 사용자에게 검색이 보여지도록 하기 위해, 안드로이드 프레임워크는 애플리케이션들이 검색되어지는 방법을 제어하게끔하는 API들을 제공한다. 애플리케이션은 검색이 호출되는 방법, 검색 다이얼로그가 보이는 방법, 그리고 사용자가 타이프할 때 제시되는 추천어suggestions를 포함해서 어떤 유형의 검색 결과들이 유용한지를 커스터마이징할 수 있다.
In order to utilize the Android search framework, an application must provide a search configuration
in the form of an XML resource.
This section describes the search configuration XML in terms of its syntax and usage. For a more
complete discussion about how to implement search features for your application, see
SearchManager.
애플리케이션은 안드로이드 검색 프레임워크를 사용하기 위해 XML 리소스 형식으로 검색 설정configuration을 제공해야 한다. 이 섹션은 검색 설정configuration XML의 구문과 사용에 대해 설명한다. 여러분의 애플리케이션이 검색 기능을 사용하는 방법에 대한 더 완벽한 논의에 대해서는 SearchManager를 보라.
Source file format:
XML file requiring a <?xml version="1.0" encoding="utf-8"?>
declaration, and a root <searchable> element.
소스 파일 포맷: XML 파일은 <?xml version=”1.0” encoding=”utf-8”?> 선언과 루트 <searchable> 엘리먼트를 요구한다.
Resource source file location: res/xml/searchable.xml
(The file name is arbitrary, but standard practice is to use searchable.xml.)
리소스 소스 파일 위치: res/xml/searchable.xml (파일 이름은 상관없으나, 표준 사례는 searchable.xml을 사용하는 것이다.)
Compiled resource datatype: Resource pointer to an xml object.
컴파일된 리소스 데이터타입: xml 오브젝트에 대한 리소스 포인터.
Resource reference name:
리소스 레퍼런스 이름:
R.xml.filename.
@[package:]xml/filename (e.g., @xml/searchable).
Syntax
구 문
<searchable xmlns:android="http://schemas.android.com/apk/res/android
android:label="@string/search_label"
... >
<actionkey
android:keycode="KEYCODE_CALL"
... >
</searchable>
More than one of the above values for searchMode can be used at once. For
example, you can declare two modes at once, like this:
searchMode="queryRewriteFromData|queryRewriteFromText"
inputType for a list of suitable values for this attribute.
imeOptions for a list of suitable values for this attribute.
If you have defined a content provider to generate search suggestions, you need to
provide some more searchable metadata in order to configure communications with the content
provider. The following are additional <searchable> attributes for use when
providing search suggestions:
Intent when the
user clicks a suggestion.
Intent when the user clicks
a suggestion.
Beyond providing search suggestions while using your application's local search, you
can also configure your search suggestions to be made available to Quick Search Box,
which will allow users so receive search suggestions from your application content from outside
your application. The following are additional <searchable> attributes for use when
providing search suggestions to Quick Search Box:
To enable voice search for your Activity, you can add fields to the searchable metadata
that enable and configure voice search. The following are additional <searchable>
attributes for use when implementing voice search:
RecognizerIntent.
If provided, this specifies the language model that
should be used by the voice recognition system. See
EXTRA_LANGUAGE_MODEL for more
information. If not provided, the default value
LANGUAGE_MODEL_FREE_FORM will be used.
Locale.
If provided, this specifies the spoken language to be expected.
This is only needed if it is different from the current value of
getDefault().
ACTION_SEARCH Intent that is passed to your
searchable Activity. To examine the key code, use
getIntExtra(SearchManager.ACTION_KEY).
Note that, in addition to the keycode, you must also provide one or more of
the action specifier attributes below.
ACTION_SEARCH Intent that is
passed to your searchable Activity. To examine the string, use
getStringExtra(SearchManager.ACTION_MSG).
ACTION_SEARCH Intent that is passed to your
searchable Activity. To examine the string,
use getStringExtra(SearchManager.ACTION_MSG).
ACTION_SEARCH
Intent that is passed to your searchable Activity. To examine
the string, use getStringExtra(SearchManager.ACTION_MSG). If the data does not exist for the
selection suggestion, the action key will be ignored.
searchMode에 대한 위의 값들 중 한 개 이상이 한번에 사용될 수 있다. 예를들어, 여러분은 아래와 같이 한번에 두개의 모드를 선언할 수 있다. searchMode="queryRewriteFromData|queryRewriteFromText"
만약 여러분이 검색 추천어suggestions를 생성하기 위해 컨텐트 프로바이더를 정의했다면, 여러분은 컨텐트 프로바이더와의 커뮤니케이션을 설정하기 위해 약간 더 많은 searchable 메타데이터를 제공할 필요가 있다. 다음에 나오는 것이 검색 추천어suggestsions를 제공할 때 사용할 추가적인 <searchable> 애트리뷰트들이다.
여러분의 애플리케이션의 로컬 검색을 사용하는 동안 검색 추천어suggestions 제공을 넘어서, 여러분은 또한 Quick Search Box(역주: 홈 런처에 있는 검색창)에서 여러분의 검색 추천어suggestions가 유용하도록 설정할 수 있다. 이것은 사용자가 여러분의 애플리케이션 외부에서 여러분의 애플리케이션 컨텐트로부터 검색 추천어suggestions를 수신하는 것을 가능하게 할 것이다. 다음에 나오는 것이 Quick Search Box에 검색 추천어suggestions를 제공할 때 사용하는 추가적인 <searchable> 애트리뷰트들이다.
여러분의 액티비티에 대한 음성 검색을 활성화하기 위해, 여러분은 음성 검색을 활성화하고 설정하는 searchable 메타데이터에 필드들을 추가할 수 있다. 다음에 나오는 것이 음성 검색을 구현할 때 사용하는 추가적인 <searchable> 애트리뷰트들이다.