Android 입문 스타일 과 Theme 용법 인 스 턴 스 분석

5889 단어 AndroidStyleTheme
현재 의 인터넷 발전 을 보면 점점 더 많은 인터넷 기업 들 이 안 드 로 이 드 플랫폼 에 클 라 이언 트 를 배치 하고 사용자 체험 을 향상 시 키 기 위해 이런 클 라 이언 트 들 은 구조 가 합 리 적 이 고 아름 답 게 만 들 었 다.본 고 에서 소개 하고 자 하 는 안 드 로 이 드 의 Style 디자인 은 사용자 체험 을 향상 시 키 는 관건 중 하나 이다.Android 의 Style 은 두 가지 로 나 뉜 다.
1.Theme 는 창 단 계 를 대상 으로 창 스타일 을 바 꿉 니 다.
2.Style 은 창 요소 단 계 를 대상 으로 지정 한 컨트롤 이나 Layout 스타일 을 변경 합 니 다.
Android 시스템 의 themes.xml 과 style.xml(/base/core/res/res/values/에 있 음)은 시스템 이 정의 한 style 을 많이 포함 하고 있 습 니 다.그 중에서 적당 한 것 을 골 라 서 수정 을 계승 하 는 것 을 권장 합 니 다.아래 의 이 코드 속성 은 Themes 에서 흔히 볼 수 있 는 것 으로 Android 시스템 자체 의 themes.xml 에서 기원 합 니 다.

<!-- Window attributes -->
<item name="windowBackground">@android:drawable/screen_background_dark</item>
<item name="windowFrame">@null</item>
<item name="windowNoTitle">false</item>
<item name="windowFullscreen">false</item>
<item name="windowIsFloating">false</item>
<item name="windowContentOverlay">@android:drawable/title_bar_shadow</item>
<item name="windowTitleStyle">@android:style/WindowTitle</item>
<item name="windowTitleSize">25dip</item>
<item name="windowTitleBackgroundStyle">@android:style/WindowTitleBackground</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>

컨트롤 의 Style 디자인 은 범위 가 넓 습 니 다.Eclipse 의 Android 컨트롤 속성 편집기[Properties]를 보면 어떤 항목 이 있 는 지 대충 알 수 있 습 니 다.Android 에 내 장 된 style.xml 도 모든 컨트롤 의 기본 스타일 을 정의 할 뿐 입 니 다.그러나 컨트롤 의 style 은 크게 바 꾸 는 것 을 권장 하지 않 습 니 다.오래 볼 수 있 는 style 은 사용자 로 하여 금 소프트웨어 를 장시간 사용 하 게 할 수 있 습 니 다.또한,컨트롤 의 Style 은 9.png 를 많이 사용 합 니 다.9.png 를 배우 면/base/core/res/res/drawable-hdpi 에 가 봐 야 합 니 다.시스템 에 내 장 된 9.png 가 많 습 니 다.
메모:안 드 로 이 드 의 Style 과 Theme 를 연구 하기 위해 안 드 로 이 드 의 base.git 를 다운로드 하 는 것 을 강력 히 권장 합 니 다!
먼저 본 고의 프로그램의 효 과 를 살 펴 보 자.다음 그림 과 같다.

이 프로그램의 themes.xml 코드 는 다음 과 같 습 니 다.Window Title 을 사용자 정의 하 였 습 니 다.

<?xml version="1.0" encoding="UTF-8"?>
<resources>
 <!--  Android   Theme.Light,  /base/core/res/res/values/themes.xml -->
 <style name="Theme" parent="android:Theme.Light">
 <item name="android:windowFullscreen">true</item>
 <item name="android:windowTitleSize">60dip</item>
 <item name="android:windowTitleStyle">@style/WindowTitle</item>
 </style>

 <style name="WindowTitle" parent="android:WindowTitle">
 <item name="android:singleLine">true</item>
 <item name="android:shadowColor">#BB000000</item>
 <item name="android:shadowRadius">2.75</item>
 </style>
</resources>

Activity 에 theme 를 사용 하려 면 코드 setTheme(R.style.Theme)을 사용 하거나 Application Manifest 에 다음 과 같이 설정 하 십시오.

본 프로그램의 styles.xml 코드 는 다음 과 같 습 니 다.background 는 기본적으로 9.png 를 사용 하고 xml 는/base/core/res/res/drawable/아래 에 정의 합 니 다.

<?xml version="1.0" encoding="UTF-8"?>
<resources>
 <style name="TextView">
 <item name="android:textSize">18sp</item>
 <item name="android:textColor">#008</item>
 <item name="android:shadowColor">@android:color/black</item>
 <item name="android:shadowRadius">2.0</item>
 </style>

 <style name="EditText">
 <item name="android:shadowColor">@android:color/black</item>
 <item name="android:shadowRadius">1.0</item>
 <item name="android:background">@android:drawable/btn_default</item>
 <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
 </style>

  <style name="Button">
    <item name="android:background">@android:drawable/edit_text</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
  </style>
</resources>

main.xml 코드 는 다음 과 같 습 니 다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <TextView android:layout_width="fill_parent"
 android:layout_height="wrap_content" android:text="@string/hello"
 style="@style/TextView" />
 <EditText android:id="@+id/EditText01" android:layout_height="wrap_content"
 style="@style/EditText" android:layout_width="fill_parent"
 android:text="  Button EditText"></EditText>
 <EditText android:id="@+id/EditText02" android:layout_height="wrap_content"
 android:layout_width="fill_parent" android:text="   EditText"></EditText>
 <Button android:id="@+id/Button01" android:layout_height="wrap_content"
 style="@style/Button" android:layout_width="fill_parent" android:text="  EditText Button"></Button>
</LinearLayout>

좋은 웹페이지 즐겨찾기