2016-09-04 60 views
-1

我即將開發一個Android應用程序。在我的應用程序中,我需要將操作欄放在屏幕的底部。我從來沒有這樣做過。我害怕開始引用我發現的鏈接,因爲大多數鏈接都建議使用自定義佈局,比如RelativeLayout和LinearLayout,因爲操作欄不能放在底部。我可以在Android的底部放置一個操作欄嗎?

但問題是我會把使用Recycler View的無限列表。我擔心的是如果使用RelativeLayout或LinearLayout,如果列表太長,操作欄可能不會固定在屏幕的底部。所以我試圖使用自定義零食。

但我覺得不是好主意,因爲小吃店不是這樣用的。但是現在大多數應用都在底部使用操作欄。我想知道的是在我的情況下底部使用操作欄的最佳方式是什麼。我從來沒有把行動欄放在底部。你會建議什麼?

+0

使用[底部導航欄(https://stackoverflow.com/a/46251598/3681880),而不是一個操作欄。 – Suragch

回答

0

在您的xml文件中創建自定義佈局和android:layout_alignParentBottom="true"。那麼在你的列表集android:layout_marginBottom="50dp"中考慮自定義佈局的高度是50dp

3

使用Support ToolBar。在佈局中手動添加工具欄xml並且 將佈局設置在底部。

 <android.support.v7.widget.Toolbar 
     android:id="@+id/my_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:elevation="4dp" 
     android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

使用NoActionBar主題風格

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

然後在活動設置支持工具欄這樣

// Find the toolbar view inside the activity layout 
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar); 
    // Sets the Toolbar to act as the ActionBar for this Activity window. 
    // Make sure the toolbar exists in the activity and is not null 
    setSupportActionBar(toolbar); 
在活動

,並覆蓋OnCreateOptionsMenu(Menu menu)

@Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_home, menu); 
    return true; 
} 

Screenshot

+0

我在你的回答中沒有看到你如何在View的底部設置佈局...請指教。 – AJW

+0

'android.support.v7.widget.Toolbar'只是一個視圖。將此視爲視圖並將此「工具欄」放置在其他視圖的底部。 –

+0

好吧,所以這應該工作得很好:'android:layout_alignParentBottom =「true」'在xml文件中? – AJW

相關問題