Layout Xml로 구현한 Layout 속성 (width, height, weight, marginLeft, marginRight)이 있습니다.

<EditText android:id="@+id/saved"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/something"
    android:layout_marginLeft="10sp"
    android:layout_marginRight="10sp"
    android:layout_weight="1"
    android:background="@drawable/green"
    android:text="@string/initial_text"
    android:freezesText="true">
    <requestFocus />
</EditText>

위의 Layout Xml로 구현한 Layout 속성을 동적 코드로 만들면 아래와 같습니다.

EditText content = new EditText(getBaseContext());
MarginLayoutParams marginCotent = new ViewGroup.MarginLayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT );
marginCotent.setMargins( 1, 1, 0, 0 );
content.setLayoutParams( new LinearLayout.LayoutParams( marginCotent ) );
content.setBackgroundColor(Color.LTGRAY);
content.setGravity(Gravity.LEFT);
content.setFreezesText(true);
content.requestFocus();

마진 수치가 완전히 일치하진 않습니다. 유의하기 바랍니다.
눈여겨 볼게 하나 있는데 requestFocus 되어 있으면 해당 텍스트에디터에 자동 포커싱되게 됩니다.

Posted by 빈솔B
,
사용자가 만든 컬러 코드는 왜 안먹히고 안드로이드 내장 라이브러리 컬러 코드는 먹히는가?

사용자가 만든 컬러코드 res/values/color.xml 내부 코드 입니다.
<resources>  
<color name="solid_red">#f00</color>
<color name="solid_blue">#0000ff</color>
<color name="solid_green">#f0f0</color>
<color name="solid_yellow">#ffffff00</color>
</resources>

아래와 같이 xml 레이아웃 통한 설정은 잘 동작합니다.
<LinearLayout 
...
android:background="#ffffffff"
...
/>

하지만 아래와 같이 동적생성일 경우엔 오브젝트 생성후 속성 세팅으로는 이상하게 커스텀 컬러 코드로는 동작하지 않습니다. 안드로이드 내장 라이브러리 컬러 코드로 해야 적용이 제대로 됩니다.
LinearLayout info = new LinearLayout(this);

//customer Resource.Color
info.setBackgroundColor(R.color.solid_yellow);

//Android.graphics.Color
info.setBackgroundColor(Color.WHITE);

왜이럴까;; 원래 이런건가;;
언젠가 알날이 오것지.. 씁쓸하구만.. 아깝다 내 두시간..
Posted by 빈솔B
,
AndroidManifest.xml 에서 아래와 같이 수정하거나  
<activity android:name=".ActivityName" 
android:label="Activity Label" 
android:theme="@android:style/Theme.NoTitleBar">
</activity>

소스 단에서
requestWindowFeature(Window.FEATURE_NO_TITLE);
해줘도 됩니다. 하지만 주의 할 점은 AndroidManifest.xml 에 타이틀 안쓰게 세팅해 놓고 소스단에서는 타이틀 바를 사용할려면 런타임오류가 납니다.


나만의 타이틀 바(Custom Title Bar)를 만들어 보기입니다.

* 소스로 구현하기
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.bloglist);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.bloglist_title);
TextView leftTitle = (TextView) findViewById(R.id.left_text);
title.setText("My Blog List");
TextView rightTitle = (TextView) findViewById(R.id.right_text);
rightTitle.setText("daum");

* UI로 구현하기
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/screen"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <!-- TextView android:id="@+id/left_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"/>
    <TextView android:id="@+id/right_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"/> -->
<ImageView
android:id="@+id/title"
android:src="@drawable/title_tistory"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />      
</RelativeLayout>




Posted by 빈솔B
,