android - kotlin Android Studio 标签布局
问题描述
- 问题1)如何删除tablayout的边框线?
- 问题2)如何设置操作栏图标的填充?
这里是activity_main.xml中的代码:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg2"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorTransparent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@android:color/transparent"
app:tabIndicatorHeight="0dp"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
这里是我在 Main_Activity.kt 文件中编写的代码:
//动作条
val actionBar = supportActionBar
actionBar!!.setDisplayShowHomeEnabled(true)
actionBar.setBackgroundDrawable(ColorDrawable(Color.parseColor("#00FFFFFF")))
actionBar.setIcon(R.drawable.title)
actionBar.setDisplayShowTitleEnabled(false)
解决方案
- 您可以为操作栏创建自定义布局,让您控制图标的外观。但是,由于这样做会遇到数百万个问题,我是否可以建议您从 using
ActionBar
转移到 API 21 中引入的它的继任者 ,Toolbar
您应该使用它:
https://guides.codepath.com/android/Using-the-App-ToolBar
借助设计库,您可以轻松地在 中引入完全可定制的工具栏CoordinatorLayout
,并做一些很酷的事情。
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentInsetStart="0dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qpon_drawable"
android:layout_margin="20dp"
android:layout_gravity="center"/>
</FrameLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@android:color/transparent"
app:tabIndicatorHeight="0dp"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabGravity="fill"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
我可以添加我想要的任何边距,并且app:contentInsetStart="0dp"
没有开始填充。您可以将工具栏添加为代码中的支持操作栏:
// Find the toolbar view inside the activity layout
Toolbar toolbar = (Toolbar) findViewById(R.id.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);
- 当我将背景颜色设置
AppBarLayout
为透明时,我遇到了同样的边框问题:
当我将背景设置为与AppBarLayout's
背景相同的颜色时,它似乎在边缘绘制并且边框消失了。请记住,它会自动在底部给它一个阴影,因为它高于Viewpager
:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<!-- This is what you want to change !-->
android:background="@android:color/background_light"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
侧面不再有边框。我不太清楚它为什么会这样,如果你不上色的话,它似乎是一种自然形式的卡片布局。
希望能帮助到你。无论您的推理如何,请尝试更改为工具栏,我认为这是唯一正确的答案!
推荐阅读
- php - 如何在全局范围内将所有 Eloquent 时间戳视为包括时区
- java - 如何根据另一个 TextView 的内容有条件地启用 TextView?
- java - Firebase 初始化未启动
- javascript - 如何从已加载的资产中检索 SVG 数据?
- c# - 在 Unity 中实现对话系统的问题
- php - 什么是最短的路
- java - JPanel、2D 图形和 MouseListener 遇到问题
- tensorflow - 卷积神经网络得到一个值错误
- wpf - 是否可以更改 WPF 元素的边界?
- ios - 错误 ibtoold[1345:11688] 调试:添加到环境:(在 IOS 中运行 xamarin 表单时出错)