안드로이드 밑부분 메뉴 표시줄 구현

5520 단어
안드로이드 프로그램은 많은 경우에 메뉴 표시줄을 밑이나 위에 표시해야 하지만 프로그래머가 호출할 수 있도록 잘 만들어지지 않았습니다. 아래에 있는 메뉴 표시줄을 실현하기 위해 보기를 사용자 정의했습니다. 효과는 다음과 같습니다.
구현된 주요 코드:
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);         linearLayout = (LinearLayout) findViewById(R.id.home);
        linearLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                linearLayout
                        .setBackgroundResource(R.drawable.tab_two_highlight);
                publish.setBackgroundResource(R.drawable.tab_one_normal);
                change.setBackgroundResource(R.drawable.tab_one_normal);
                more.setBackgroundResource(R.drawable.tab_one_normal);
            }
        });
        linearLayout
        .setBackgroundResource(R.drawable.tab_two_highlight);         publish = (LinearLayout) findViewById(R.id.publish);
        publish.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                publish.setBackgroundResource(R.drawable.tab_two_highlight);
                linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
                change.setBackgroundResource(R.drawable.tab_one_normal);
                more.setBackgroundResource(R.drawable.tab_one_normal);
            }
        });         change = (LinearLayout) findViewById(R.id.change);
        change.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                change.setBackgroundResource(R.drawable.tab_two_highlight);
                linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
                publish.setBackgroundResource(R.drawable.tab_one_normal);
                more.setBackgroundResource(R.drawable.tab_one_normal);
            }
        });         more = (LinearLayout) findViewById(R.id.more);
        more.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                more.setBackgroundResource(R.drawable.tab_two_highlight);
                linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
                publish.setBackgroundResource(R.drawable.tab_one_normal);
                change.setBackgroundResource(R.drawable.tab_one_normal);
            }
        });
    }

프로파일 구현:
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    android:orientation=”horizontal” android:layout_width=”fill_parent”
    android:layout_height=”wrap_content”>
    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
        android:orientation=”vertical” android:layout_width=”80px”
        android:layout_height=”wrap_content” android:id=”@+id/home”
        android:background=”@drawable/tab_one_normal”>
        <TextView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:text=”@string/home”
            android:gravity=”center” android:paddingTop=”29px”
            android:background=”@drawable/home” />
    </LinearLayout>
    <ImageView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:src=”@drawable/line” />
    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
        android:orientation=”vertical” android:layout_width=”80px”
        android:layout_height=”wrap_content” android:background=”@drawable/tab_one_normal”
        android:id=”@+id/publish”>
        <TextView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:text=”@string/publish”
            android:gravity=”center” android:paddingTop=”29px”
             android:background=”@drawable/publish” />
    </LinearLayout>
    <ImageView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:src=”@drawable/line” />
    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
        android:orientation=”vertical” android:layout_width=”80px” android:id=”@+id/change”
        android:layout_height=”wrap_content” android:background=”@drawable/tab_one_normal”>
        <TextView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:text=”@string/change”
            android:gravity=”center” android:paddingTop=”29px”
             android:background=”@drawable/change” />
    </LinearLayout>
    <ImageView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:src=”@drawable/line” />
    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
        android:orientation=”vertical” android:layout_width=”80px” android:id=”@+id/more”
        android:layout_height=”wrap_content” android:background=”@drawable/tab_one_normal”>
        <TextView android:layout_width=”wrap_content”
            android:layout_height=”wrap_content” android:text=”@string/more”
            android:gravity=”center” android:paddingTop=”29px”
             android:background=”@drawable/more” />
    </LinearLayout>
</LinearLayout>
    :http://easymorse.googlecode.com/svn/trunk/android.bottom
 

좋은 웹페이지 즐겨찾기