我正在尝试将按钮添加到 android studio 应用程序中的操作栏到子 Activity ,但我只能设法将其添加到主要 Activity 。有人知道我该怎么做吗?
我希望“确定”按钮位于我用橙色绘制的位置。
最佳答案
您不必使用操作栏。您只能使用您想要的背景颜色的 View 。在您将按钮设置在彩色区域上方之后。
在 Android Studio 中:
值(value)观>风格
使用这个:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
代替
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
回到你的布局:
// Change your background with LinearLayout's background propoerty
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFA908"
>
// You can put here whatever you want. İf you wish image or button.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example"
android:layout_gravity="center"
android:layout_marginLeft="200dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example"
android:layout_gravity="center"
/>
</LinearLayout>
İf 你可以像这样使用。您不需要使用操作栏。您可以轻松创建任何您想要的内容。
关于java - 有没有一种简单的方法可以将按钮添加到子 Activity 的操作栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56894237/