我有一个包含文本视图和复选框的线性布局。
<LinearLayout style="@style/linearLayoutStyleNoBgColor" >
<TextView
android:id="@+id/useFollowupDate"
style="@style/textFieldStyleType1WithCheckbox" />
<CheckBox
android:id="@+id/checkFollowDate"
style="@style/checkboxStyleType1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
样式是:
<style name="linearLayoutStyleNoBgColor">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_margin">5dp</item>
<item name="android:weightSum">1.0</item>
</style>
<style name="textFieldStyleType1WithCheckbox" parent="@style/textFieldStyleType1">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">0.30</item>
<item name="android:gravity">center_vertical</item>
</style>
<style name="checkboxStyleType1">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">0.70</item>
<item name="android:gravity">right|end</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是
TextView | checkbox
(30%percent screen) | (to the right)
Run Code Online (Sandbox Code Playgroud)
但我现在得到的是
TextView | checkbox
(30%percent screen) | (left aligned)
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
android android-layout android-linearlayout android-checkbox android-styles
之间有什么区别
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
和
<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
注意 using@android:style/和 just using的父语法的不同android:。
我已经在 android 布局 xml 文件中看到了“?android:”和“@android:”之间的区别是什么?但请注意,我的示例不包含问号。
我想创建两个主题,GrayTheme和RedTheme,它们修改一个样式属性.例如,这里是我的两个主题,默认字体颜色是白色,这对两个主题都很好:
<style name="RedTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
<style name="GrayTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是我有一种用于Header TextViews的样式.如果我使用的是RedTheme,我希望样式HeaderFont的textColor为红色,如果是GrayTheme,我希望HeaderFont textColor为灰色,而不必修改访问此HeaderFont样式的各个xml文件.
<style name="HeaderFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/gray</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我一直在寻找一个优雅的解决方案,但一直找不到任何东西.想法?
用户可选的主题(亮和暗),用具有其自己的资源的每个主题,是直接实现如果单个父主题是在该应用中使用:
<style name="MyApp.Dark" parent="android:Theme.Material">
<item name="themeBackground">@color/dark_grey</item>
<item name="themeBackgroundTransparent">@color/darkColorBackgroundTransparent</item>
<item name="colorPrimary">@color/darkColorPrimary</item>
.
.
</style>
<style name="MyApp.Light" parent="android:Theme.Material.Light">
<item name="themeBackground">@color/brown_50</item>
<item name="themeBackgroundTransparent">@color/lightColorBackgroundTransparent</item>
<item name="colorPrimary">@color/lightColorPrimary</item>
.
.
</style>
Run Code Online (Sandbox Code Playgroud)
但是,典型的Android应用可能会在整个应用中采用多个父主题,例如对话框主题,无操作栏主题或大对话框对话框。当前扩展的主题不会覆盖这些主题Theme.Material(因为继承是昂贵的),因此使用这些主题将需要为浅色和深色主题添加其他样式定义:
<style name="MyApp.DialogWhenLarge.Light" parent="android:Theme.Material.Light.DialogWhenLarge">
</style>
<style name="MyApp.DialogWhenLarge.Dark" parent="android:Theme.Material.DialogWhenLarge">
</style>
Run Code Online (Sandbox Code Playgroud)
为了将主题资源应用于新主题,简单的解决方案是将MyApp.Dark主题中的单个项目复制并粘贴到新MyApp.DialogWhenLarge.Dark主题中,等等,但是随着代码数量的增加,重复代码的数量变得难以管理,难以理解且容易出错主题和资源。
所以我的问题是,将主题资源应用于多个主题定义的简单方法是什么?
理想情况下,可以将一种资源应用于主题的方式与将样式应用于视图的方式相同,这将导致以下形式的解决方案:
<style name="MyApp.DialogWhenLarge.Light" parent="android:Theme.Material.Light.DialogWhenLarge">
<item name="themedResources">[pointer to canonical list of light theme resources]
</style>
Run Code Online (Sandbox Code Playgroud)
当然,任何解决方案都必须保留以以下格式从视图引用主题资源的功能,这一点也很重要。 ?themeBackground
我的安卓应用:
目标 AP I:22
最小 API : 15
设备运行于:API 级别22
我不明白整个主题概念,
在我的manifest.xml,我已经设置 android:theme="@style/AppTheme"
并且所有活动都使用这个主题
现在我的理解是,他们都使用名为的主题AppTheme,我现在可以通过在我的内部扩展其他主题来定义styles.xml
在我的 styles.xml
我有这个
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
我的理解是, AppCompat主题也允许我们在旧设备上使用更新的(比如材料主题)。我在 API Level 22 和 API Level 15 上运行这个应用程序,它工作正常
现在当我把它改成
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
它给出了一个警告,说这个主题只能在 API 21 或更高版本上使用,这是正确的,现在当我忽略警告并在 API 22 上运行它时,它会崩溃。为什么?
我还尝试将 …
android android-compatibility android-theme android-studio android-styles
我正在使用 RecyclerView 作为列表。我找到了一个非常好的解决方案来提供列表点击反馈和涟漪(在棒棒糖上)。基本上我给我的行布局属性:
android:background="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了我的列表需要不同的背景颜色(默认状态)。如何仅覆盖基本状态背景(未单击)并为其赋予不同的颜色?
我刚刚更新了build.gradle(Module:app)dependecies,之后在Android Studio上出现了渲染问题.有什么不对,在更新依赖关系之前,everythink工作正常
现在是这样的:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
}
Run Code Online (Sandbox Code Playgroud)
my_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:layout_marginTop="4dp"
android:paddingTop="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/myPager"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="120dp"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:elevation="4dp"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="70dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:statusBarScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/appToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
<android.support.design.widget.TabLayout
style="@style/AppTheme.TabLayout"
android:id="@+id/appTabs"
android:scrollbars="horizontal"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
并得到这个错误:
Rendering Problems Missing styles. …Run Code Online (Sandbox Code Playgroud) 所以我试图为我的 android 应用程序使用统一的自定义主题,想法是在应用程序加载时(在统一徽标之前)更改颜色(甚至添加图像),因为一些低端设备正在使用最多 10 秒来显示启动画面,而 10 秒的黑屏只会让应用看起来像是坏掉了。
到目前为止,我的 android 清单有:
android:theme="@style/CustomTheme"
Run Code Online (Sandbox Code Playgroud)
我有另一个带有样式的文件:
<resources>
<style name="CustomTheme" parent="@android:style/Theme.Material.NoActionBar.Fullscreen">
<item name="android:windowBackground">@drawable/editor_bg</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
每当我更改样式的父项时,对 Theme.Translucent.NoTitleBar 说,我会看到更改,我的应用程序会删除黑屏,因此我知道样式已更改/使用。
我的问题是 @drawable/editor_bg 似乎根本不起作用,我什至尝试使用颜色而不是在另一个文件中定义的带有 @color/white 的图像。
不确定这是统一本身的问题(使用 5.3.1 个人版)还是在 android 方面遗漏了一些东西。任何帮助表示赞赏。
android unity-game-engine android-manifest android-theme android-styles
我一直在尝试更改 progressBar 的颜色,并且我注意到它使用了重音颜色(在我的情况下为蓝色),并且我一直试图在没有运气的情况下更改它。
我错过了什么吗?
这是在我的styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="searchViewStyle">@style/AppTheme.SearchView</item>
<item name="editTextColor">@android:color/white</item>
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
<item name="actionOverflowButtonStyle">@style/AppTheme.OverFlowItem</item>
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="colorAccent">@color/ColorPrimaryDark</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是我在 layout.xml 中的元素
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/Widget.AppCompat.ProgressBar"
android:id="@+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
Run Code Online (Sandbox Code Playgroud)
我的活动:
public class MainActivity extends android.support.v7.app.AppCompatActivity
Run Code Online (Sandbox Code Playgroud) 我正在为我的AlertDialogs使用自定义样式,但它使它们显示为全屏。我四处搜索,但我似乎只能找到想要全屏显示的人......
这是我的风格
<style name="MyDialog" parent="AlertDialog.AppCompat">
<item name="android:background">@color/material_dark</item>
<item name="android:layout_height">100dp</item>
<item name="android:textColor">@color/accent</item>
<item name="android:textColorPrimary">@color/material_white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
还有我AlertDialog的一个。
AlertDialog alertDialog = new AlertDialog.Builder(this.getContext(), R.style.MyDialog)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(this.getContext().getResources().getString(R.string.reset) + "?")
.setMessage(this.getContext().getResources().getString(R.string.AreYouSure))
.setPositiveButton(getString(R.string.yes), (dialog, which) -> {
reset();
})
.setNegativeButton(getString(R.string.notReally), (dialog, which) ->{
//Do nothing
})
.show();
Run Code Online (Sandbox Code Playgroud)
这就是它的样子。我不知道为什么它占据了整个屏幕。它应该看起来像AlertDialog自定义颜色。
android presentation android-alertdialog android-styles android-5.0-lollipop