2016-05-31 160 views
1

我想玩一些Android代碼第一次。我在開始時一直關注Hello World示例,直到您創建文本輸入爲止,然後啓動其他Activity並通過按發送按鈕發送文本輸入內容活動。工具欄不顯示android

現在我想爲導航添加一個底部工具欄,以便實現一個空的活動,它是單獨定義工具欄的,然後在我的主要活動中執行。但是,正如你所看到的,沒有任何工具欄出現,但是我的文本輸入本身已經消失了,我的發送按鈕現在出現在其他地方......我並不真正知道我在做什麼,說實話,如果我能得到一些解釋,我會高度欣賞它:

更新:我已經嘗試從@prat的解決方案看到附加的新截圖。

更新2:通過將relativelayout設置爲垂直而不是水平來解決。

enter image description here

enter image description here

最終什麼,我想實現的是從谷歌的材質設計準則底部類似於更新的導航欄一欄:

enter image description here

+0

您已將方向設置爲水平。你是否將它設置爲'MyActivity.java'中的工具欄? –

+0

我看不到它說它是水平的,而不是水平導航欄的重點?另外爲什麼MyActivity.java? –

+0

您的LinearLayout設置爲水平。這就是爲什麼它是在正確的而不是底部。這裏是一個工具欄的例子:http://stackoverflow.com/a/30063604/4583267 –

回答

1

對於底部toolbar.try此代碼。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:layout_alignParentBottom="true" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="16dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="hello_android" /> 
    </RelativeLayout> 
</RelativeLayout> 
+0

我已經使用@prat的解決方案更新了上面的帖子,似乎沒有辦法,你知道什麼是錯的嗎? –

+0

@FlorianMonfort試試這個github鏈接https:// github。com/DevLight-Mobile-Agency/NavigationTabBar –

+1

我寧願不使用預先構建的框架,但自己學習如何做到這一點,即使它不如 –

1

工具欄在底部,像這樣嘗試

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:minHeight="?attr/actionBarSize" 
    android:background="@color/primaryBlue" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 

main.xml中

<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="wrap_content" 
    android:orientation="vertical" 
    tools:context="com.ahotbrew.toolbar.MainActivity"> 

    <include 
     layout="@layout/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="16dp"> 

     <TextView 
      android:text="hello_brew" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"/> 
    </RelativeLayout> 
</RelativeLayout> 
+0

我想你的解決方案,但我似乎有一個顏色屬性的問題:行是紅色和AS表示「無法解析符號@ color/primaryBlue「...? –

+0

對於顏色,你必須提及color.xml文件中的顏色。 U可以提到你自己的顏色,可以調用xml – prat

+0

Arf我不能在這裏顯示結果,但它並沒有真正做我所期望的... –