1 2 3 4 5 6 7 | String returnUrl; try { returnUrl = new String(request.getSession().getAttribute( "returnUrl" ).toString()); } catch (Exception e){ LogFile.write( "Url exception: " + e.toString()); } Out.println(returnUrl); |
[java] try catch와 class memory 및 scope 개념
[Android] xml에서 question mark(?), 물음표의 의미
question mark(?)를 이용하여 xml에서 현재 테마에 맞춰 값을 설정 할 수 있다.
?android:textColorSecondary
?android:attr/textColorSecondary
동일한 의미이며 values/attrs.xml에 설정된 attribute를 이용하는데 이때 해당하는 attribute에 대한 세부 설정은 theme_base.xml에 설정되어있다.
android-support-v7-appcompat
를 예시로 들면
•res/layout/abc_action_bar_home.xml
android:src="?attr/homeAsUpIndicator"
•res/values/attrs.xml
<!-- Specifies a drawable to use for the 'home as up' indicator. -->
<attr name="homeAsUpIndicator" format="reference"/>
•res/values/themes_base.xml
<item name="homeAsUpIndicator">@drawable/abc_ic_ab_back_holo_dark</item>
위와 같은 방식으로 사용하고 있다.
Referencing style attributes
A style attribute resource allows you to reference the value of an attribute in the currently-applied theme. Referencing a style attribute allows you to customize the look of UI elements by styling them to match standard variations supplied by the current theme, instead of supplying a hard-coded value. Referencing a style attribute essentially says, "use the style that is defined by this attribute, in the current theme."
To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (@
), use a question-mark (?
), and the resource type portion is optional. For instance:
?[<package_name>:][<resource_type>/]<resource_name>
For example, here's how you can reference an attribute to set the text color to match the "primary" text color of the system theme:
<EditText id="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:text="@string/hello_world" />
Here, the android:textColor
attribute specifies the name of a style attribute in the current theme. Android now uses the value applied to the android:textColorSecondary
style attribute as the value for android:textColor
in this widget. Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type (which would be ?android:attr/textColorSecondary
)—you can exclude the attr
type.
출처: http://developer.android.com/intl/ko/guide/topics/resources/accessing-resources.html
http://stackoverflow.com/a/4771871/5182144
'Programming Study > Android' 카테고리의 다른 글
[Android] xml에서 xmlns:android=“http://schemas.android.com/apk/res/android” 의 의미 (0) | 2015.08.01 |
---|---|
[Android] xml layout의 tools attribute (0) | 2015.08.01 |
uri로 xmlns:android=“http://schemas.android.com/apk/res/android”를 쓰겠다는 의미로 저 uri의 정보를 가져다 쓰겠다는 의미
To understand why xmlns:android=“http://schemas.android.com/apk/res/android”
must be the first in the layout xml file We shall understand the components using an example
Sample
::
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container" >
</FrameLayout>
Uniform Resource Indicator(URI):
- In computing, a uniform resource identifier (URI) is a string of characters used to identify a name of a resource.
- Such identification enables interaction with representations of the resource over a network, typically the World Wide Web, using specific protocols.
Ex:http://schemas.android.com/apk/res/android:id
is the URI here
- XML namespaces are used for providing uniquely named elements and attributes in an XML document.
xmlns:android
describes the android namespace. - Its used like this because this is a design choice by google to handle the errors at compile time.
- Also suppose we write our own
textview
widget with different features compared to androidtextview
, android namespace helps to distinguish between our customtextview
widget and androidtextview
widget
'Programming Study > Android' 카테고리의 다른 글
[Android] xml에서 question mark(?), 물음표의 의미 (0) | 2015.08.02 |
---|---|
[Android] xml layout의 tools attribute (0) | 2015.08.01 |