gpt4 book ai didi

android - 有没有类似风格组的东西?

转载 作者:行者123 更新时间:2023-11-30 02:07:39 24 4
gpt4 key购买 nike

我有两组 View 应该使用不同的样式,只需将它们称为 leftStyles 和 rightStyles。

这两组 View 有相同的 layout.xml ,我想通过编程改变容器的“styleGroup”来改变它所有的 child 风格,就像一个主题。是否存在可应用于布局的“ View 组级别”主题?

这两个组在同一个页面中,所以我无法用主题来区分它们。

有什么方法可以在 ViewGroup 中设置一组样式,以便它的子项可以使用这些样式?

最佳答案

希望对你有帮助。这是一种风格,你可以在其中声明你的组风格,子风格,单一风格......就像这样

<style name="Widget.Group" parent="@android:style/Widget">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">46dp</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginTop">-1dp</item> <!-- Ensures we don't get a 2 dp top stroke -->
<item name="android:padding">4dp</item>
<!--<item name="android:background">@drawable/bg_input_group</item>-->
</style>

<style name="Widget.Group.Top">
<item name="android:layout_marginTop">10dp</item>
<!--<item name="android:background">@drawable/bg_input_group_top</item>-->
</style>

<style name="Widget.Group.Bottom">

<item name="android:layout_marginTop">20dp</item>
<!--<item name="android:background">@drawable/bg_input_group_bottom</item>-->
</style>

<style name="Widget.Group.Single" parent="Widget.Group.Top">
<!--<item name="android:background">@drawable/bg_input_group_single</item>-->
</style>

和你的布局文件你cad像这样使用这种风格

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#eee">

<!-- Input Group -->
<EditText style="@style/Widget.Group.Top" />
<EditText style="@style/Widget.Group" />
<EditText style="@style/Widget.Group.Bottom" />

<!-- Single item -->
<EditText style="@style/Widget.Group.Single" />

</LinearLayout>

了解更多详情 click

关于android - 有没有类似风格组的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30449034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com