[ReadAsset.java]

import java.io.IOException;
import java.io.InputStream;


public class ReadAsset extends Activity
{
    @Override
 protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // See assets/res/any/layout/styled_text.xml for this
        // view layout definition.

        setContentView(R.layout.read_asset);

        // Programmatically load text from an asset and place it into the
        // text view.  Note that the text we are loading is ASCII, so we
        // need to convert it to UTF-16.
        try {
            InputStream is = getAssets().open("read_asset.txt");
           
            // We guarantee that the available method returns the total
            // size of the asset...  of course, this does mean that a single
            // asset can't be more than 2 gigs.
            int size = is.available();
           
            // Read the entire asset into a local byte buffer.
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
           
            // Convert the buffer into a string.
            String text = new String(buffer);
           
            // Finally stick the string into the text view.
            TextView tv = (TextView)findViewById(R.id.text);
            tv.setText(text);
        } catch (IOException e) {
            // Should never happen!
            throw new RuntimeException(e);
        }
    }
}



[StyledText.java]

    @Override
 protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // See assets/res/any/layout/styled_text.xml for this
        // view layout definition.
        setContentView(R.layout.styled_text);

        // Programmatically retrieve a string resource with style
        // information and apply it to the second text view.  Note the
        // use of CharSequence instead of String so we don't lose
        // the style info.

        CharSequence str = getText(R.string.styled_text);
        TextView tv = (TextView)findViewById(R.id.text);
        tv.setText(str);
    }
}



[Manifest.xml]

        <activity android:name=".content.ReadAsset" android:label="@string/activity_read_asset">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
                <category android:name="android.intent.category.EMBED" />
            </intent-filter>
        </activity>



[read_asset.xml]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">

    <TextView android:id="@+id/text"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textStyle="normal"/>

</LinearLayout>



[styled_text.xml]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="@string/styled_text_rsrc"/>

    <TextView
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textStyle="normal"
        android:text="@string/styled_text"/>

    <TextView
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        />

    <TextView
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:text="@string/styled_text_prog"/>

    <TextView android:id="@+id/text"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:textStyle="normal"/>

</LinearLayout>

'old > API_Demo' 카테고리의 다른 글

Text_Linkify  (0) 2010.03.25
Content_Resources_Resources  (0) 2010.03.25
APP_VoiceRecognition  (0) 2010.03.25
APP_TextToSpeech  (0) 2010.03.25
APP_Service_ServiceStartArgumentsController  (0) 2010.03.25
Posted by jazzlife
,