2010年11月13日土曜日

android: 他のアプリを起動させる(CreateProcessの意味)

アンドロイドのアプリで他のアプリを起動させるのはintentを使ったらOKです。
例のコード:
  あるアプリがtien.helloのpackageにあり、マインのアクティビティはhelloであれば呼び方は下通りです。
String clazz = "tien.hello.hello";
            Intent intent = new Intent(Intent.ACTION_MAIN);

            int idx = clazz.lastIndexOf('.');
            String pkg = clazz.substring(0, idx);

            intent.setClassName(pkg, clazz);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

2010年11月4日木曜日

Android: Add custom button on title bar(ボタンをタイトルバーに貼る)

今回、僕はボタンをタイトルに貼るアプリを作ったけど、ちょっと問題があった。コードは以下通りです。
※layoutのbuttontitlebar.xmlファイルのコード:

<#RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
    android:layout_width="wrap_content"
    android:layout_height="50dip"
    android:orientation="vertical">
    <#TextView android:id="@+id/titletext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="@string/levelname" />
    <#Button android:id="@+id/titlebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="@string/btnname" />


※アクティビティのコード:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int i;
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.buttontitlebar);
}

しかし、ボタンのサイズが調整できないため、半分だけ表示されているんです。
ボタンのサイズはどのように調整できますか。ご存知の方がいらしゃったら教えて頂きます。