2016-05-31 166 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我不能在这里显示结果,但它并没有真正做我所期望的... –

相关问题