42

Ice Cream Sandwich(Android 4.0)は、Action Bar電話の画面の下部にを表示するオプションを追加します。これは、私のアプリケーションで使用したいものです。ドキュメントuiOptions="splitActionBarWhenNarrow"には、上部にタブ、Action Bar下部にショートカットなど、何かが必要な場合について記載されています。ドキュメントで説明されているように、アプリケーションマニフェストに行を追加しようとしましたが、これまでのところ機能していません。

次に例を示します。

ここに画像の説明を入力してください

Action Barまた、ICSを実行しているGalaxy Nexusでは、メッセージングアプリケーションの下部が下部にあり、上部にタイトルしかないことに気付きました。そのため、何らかのAction Bar方法でを下部に強制することができるはずです。

何か案は?

4

5 に答える 5

28

ドキュメントに記載されているように、アプリケーションマニフェストに行を追加しようとしましたが、これまでのところ機能していません。

このサンプルプロジェクトでうまくいきました。マニフェストは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.commonsware.android.actionbarbc"
          xmlns:android="http://schemas.android.com/apk/res/android">

  <application android:hardwareAccelerated="true"
               android:icon="@drawable/cw"
               android:label="@string/app_name">
    <activity android:label="@string/app_name"
              android:name=".InflationDemo"
              android:uiOptions="splitActionBarWhenNarrow">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>
  <uses-sdk android:minSdkVersion="4"
            android:targetSdkVersion="11" />
  <supports-screens android:anyDensity="true"
                    android:largeScreens="true"
                    android:normalScreens="true"
                    android:smallScreens="true"
                    android:xlargeScreens="true" />
</manifest>

また、ICS を実行している私の Galaxy Nexus では、メッセージング アプリケーションの下部にアクション バーがあり、上部にはタイトルしかないことに気付きました。

ActionBar上部と下部にある会話リストを参照している場合はsplitActionBarWhenNarrow、次のセットアップ コードを使用します。

private void setupActionBar() {
    ActionBar actionBar = getActionBar();

    ViewGroup v = (ViewGroup)LayoutInflater.from(this)
        .inflate(R.layout.conversation_list_actionbar, null);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(v,
            new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                    ActionBar.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER_VERTICAL | Gravity.RIGHT));

    mUnreadConvCount = (TextView)v.findViewById(R.id.unread_conv_count);
}
于 2011-12-12T00:27:21.513 に答える
12

私は ActionBarSherlock を使用していますが、同様の問題がありました。タグではなく android:uiOptions="splitActionBarWhenNarrow"、タグ内に配置することで解決しました。<activity><application>

たとえば、これはうまくいきました:

<activity android:name=".my.Activity" 
          android:uiOptions="splitActionBarWhenNarrow"/>

そしてこれはうまくいきませんでした:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.slowchop.etc"
          android:uiOptions="splitActionBarWhenNarrow">
于 2012-03-25T05:37:44.777 に答える
3

タブレットの一番下に留まることを強制することはできませんが、電話の場合はマニフェストを介してそれを行うことができます. ただし、ボトムバーとトップバーに似たことができます。この例では、マージを使用して、Android ActionBar を使用しなくても簡単にそれを行う方法を示します。

最初に作成する必要があるのはmain_activity.xml、私の場合、RelativeLayoutmain_activity.xmlのみが含まれていることです。ImageViewこれがコードです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
        <RelativeLayout android:id="@+id/RelativeLayout04"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:layout_alignParentTop="true">

    <include layout="@layout/header" />

</RelativeLayout>

<ImageView
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_above="@+id/RelativeLayout03"
    android:layout_below="@+id/RelativeLayout04"
    android:layout_centerHorizontal="true"
    android:src="@android:drawable/alert_dark_frame" />

    <RelativeLayout android:id="@+id/RelativeLayout03"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <include layout="@layout/tryit" />

</RelativeLayout>

上記のコードでわかるように、main_activity.xml下部に定義されたマージと上部に定義されたマージの中に2つのマージがあります。これが偽のボトムバーxmlです。

<merge xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="80dp"
     android:layout_weight="0.14"
    android:background="@drawable/dock" >

    <ImageView
        android:id="@+id/dark"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.14" />

    <ImageView
        android:id="@+id/stock"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.14" />

    <ImageView
        android:id="@+id/open"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.14" />

    <ImageView
        android:id="@+id/border"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.15" />

    <ImageView
        android:id="@+id/color"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.15" 
        />

</LinearLayout>

私は固定の背景を入れて、LinearLayoutonClicks の ImageView を偽造しています。

そしてこれがトップバーです。`

<LinearLayout
    android:id="@+id/LinearLayout02"
    android:layout_width="match_parent"
    android:layout_height="40dp"
     android:layout_weight="0.14"
    android:background="@drawable/dock1" 
    android:layout_gravity="top">

    <ImageView
        android:id="@+id/darka"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.14" />

    <ImageView
        android:id="@+id/stocka"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.14" />

    <ImageView
        android:id="@+id/opena"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.14" />

    <ImageView
        android:id="@+id/bordera"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.15" />

    <ImageView
        android:id="@+id/colora"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="0.15" 
        />

</LinearLayout>

`

上の下部のバーからコピーして貼り付けることもできます。android:layout_alignParentBottom="true" 1 つを からに変更するだけandroid:layout_alignParentTop="true"で、下部と上部に actionBar ができます。この場合、ActionBar を使用する必要はないので、使用することをお勧めしますTheme.Holo.NoActionBar

ここに画像の結果があります:- http://i.imgur.com/N8uKg6v.png

これは私が今取り組んでいるプロジェクトです。ほぼすべての作業を完了しましたが、まだ設計に苦労しています。私の答えがあなたに役立つことを願っています。面白いと思ったら、答えに投票してください。
よろしくお願いします。〜コッシュ

于 2013-01-30T05:25:57.213 に答える
0

これを試して...

private View contentView;

@Override
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     contentView = getLayoutInflater().inflate(R.layout.activity_main, null);
     setContentView(contentView);
     LinearLayout layout = (LinearLayout) contentView.getParent().getParent();
     View view = layout.getChildAt(0);
     layout.removeViewAt(0);
     layout.addView(view);
}
于 2013-08-07T14:24:54.240 に答える