Android自定义工具栏(二)——试试Toolbar

接上篇,上篇提到要实现下面这个样子的工具栏:


主要是两个改动:一是把三个小圆点换成三个小方点,还有就是把弹出菜单的位置改到下面。

既然需要用到Toolbar这个组件,首先先在layout里加上下面这段:

    <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:layout_width="match_parent"
                                       android:layout_height="@dimen/toolbar_height"
                                       android:background="@color/colorBackground"
                                       app:contentInsetStart="0dp">
        <TextView
                android:id="@+id/toolbar_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/colorWhite"
                android:textSize="20sp"
                android:text="Hit me"/>
    </android.support.v7.widget.Toolbar>

然后在onCreate()里调用一个initToolbar()方法&#x

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cesium默认的工具栏包含了一些基本的控件,但是如果需要自定义工具栏,可以通过以下步骤实现: 1. 创建一个新的div元素,作为自定义工具栏的容器,设置其样式和位置。 2. 创建需要的控件元素,例如按钮、下拉菜单等,设置其样式和事件处理函数。 3. 将这些控件元素添加到自定义工具栏容器中。 4. 将自定义工具栏容器添加到Cesium Viewer的DOM中,可以使用Cesium的toolbarContainer属性来获取默认工具栏容器的父元素。 以下是一个简单的示例代码: ``` // 创建自定义工具栏容器 var toolbar = document.createElement('div'); toolbar.id = 'my-toolbar'; toolbar.style.position = 'absolute'; toolbar.style.top = '10px'; toolbar.style.left = '10px'; toolbar.style.zIndex = '1'; // 创建按钮控件 var button = document.createElement('button'); button.innerText = 'My Button'; button.onclick = function() { console.log('Button clicked!'); }; // 将按钮添加到工具栏容器中 toolbar.appendChild(button); // 将工具栏容器添加到Cesium Viewer中 var viewer = new Cesium.Viewer('cesiumContainer', { toolbarContainer: document.querySelector('.cesium-viewer-toolbar') }); viewer.container.appendChild(toolbar); ``` 在这个示例中,我们创建了一个ID为“my-toolbar”的div元素作为自定义工具栏的容器,设置其位置和样式。然后创建了一个按钮控件,并将其添加到工具栏容器中。最后将工具栏容器添加到Cesium Viewer中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值