标签: android-styles

Android主题 - 如何仅为特定视图类型设置样式

是否可以创建一个仅为特定视图类型设置样式的主题?例如,如果我希望FrameLayout对象的背景为一种颜色,但是将所有其他视图保留为主题的默认背景颜色,我该怎么做?

CSS并行将是div {background-color:#000000;}.我怎么能在android中做到这一点?

编辑:我发现TextView只有:android:textViewStyle,你可以只为TextViews 选择一种风格.但其他观点呢?甚至自定义视图?FrameLayout具体看?

android android-styles

10
推荐指数
0
解决办法
1333
查看次数

将style ="?android:attr/buttonBarStyle"设置为父布局,将style ="?android:attr/buttonBarButtonStyle"设置为按钮使它们不可见

我遵循Android推荐并设置style="?android:attr/buttonBarStyle" 为父布局和style="?android:attr/buttonBarButtonStyle"按钮.

所以现在我的布局是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    style="?android:attr/buttonBarStyle">

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1"
        style="?android:attr/buttonBarButtonStyle"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2"
        style="?android:attr/buttonBarButtonStyle"/>

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 3"
        style="?android:attr/buttonBarButtonStyle"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但是在设置了样式后,这些按钮变得不可见,但我仍然可以点击它们.

请告诉我有什么问题.

编辑:其他细节

好吧,我刚刚创建了一个专门用于测试此布局的新项目,并且令人惊讶的是它确实可行.

所以更准确地说,实际上,我动态地将这个布局添加到另一个布局,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/buttons_panel_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    </LinearLayout>

    <!-- some other stuff -->

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

码:

LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LinearLayout buttonsPanelContainer = (LinearLayout) findViewById(R.id.buttons_panel_container);

View buttonPanelView = null;
if(chosenValueType.equals("some_type")) {

    buttonPanelView = layoutInflater.inflate(R.layout.some_buttons_panel, null);

    Button Button1 …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-styles

10
推荐指数
1
解决办法
1万
查看次数

在棒棒糖前设备上,进度对话显得非常奇怪

我在棒棒糖前设备上的进度对话框如下所示: 在此输入图像描述

看到那个双窗口?我不知道为什么会发生这种情况.

  1. 像这样初始化进度对话框:

    progressDialog = new ProgressDialog(context);
    progressDialog.setMessage(messsage);
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在值值中定义了这样的样式-21:

<style name="AlertDialog.Theme" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:textColorPrimary">@color/black</item>
        <item name="android:background">@color/white</item>
        <item name="android:textColor">@color/black</item>
        <item name="colorAccent">@color/orange</item>
        <item name="colorPrimary">@color/orange</item>
        <item name="colorPrimaryDark">@color/darkerorance</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

  1. 在google上搜索了一些后,我在主题中添加了警报样式,如下所示:

<item name="android:dialogTheme">@style/AlertDialog.Theme</item>
        <item name="dialogTheme">@style/AlertDialog.Theme</item>
        <item name="android:alertDialogTheme">@style/AlertDialog.Theme</item>
        <item name="alertDialogTheme">@style/AlertDialog.Theme</item>
Run Code Online (Sandbox Code Playgroud)

主题延伸自Theme.AppCompat.Light.NoActionBar.

这在Lollipop及以上版本上效果很好,但在棒棒糖前的图像中看起来很像.任何人都可以帮忙,告诉我我做错了什么?

android progressdialog android-styles

10
推荐指数
1
解决办法
2740
查看次数

Android ProgressBar的样式与SwipeRefreshLayout中的进度视图类似

android.support.v4.widget.SwipeRefreshLayout在我的Android应用中使用.它包裹了一个ListView.列表视图的内容是从服务器下载的.

当用户向下滑动以从服务器重新加载数据时,将显示进度视图.进度视图看起来像一个在动画期间增长和缩小的圆圈.看来这个进度视图的风格不能定制太多.但是,我内置的风格很好.

我还在初始数据加载期间显示相同的进度动画.这可以通过致电来实现mySwipeRefreshLayout.setRefreshing(true).那也很好.

但是,我想通过整个应用程序显示相同的进度指示.考虑例如看起来像带有提交按钮的表单的另一个活动.这种形式的活动既没有ListView也没有SwipeRefreshLayout.在将提交的数据传输到服务器时,应显示一些进度指示.我想在SwipeRefreshLayout中显示具有相同动画的进度条.

是否有一种简单而干净的方法来为a SwipeRefreshLayout和表单活动提供相同的进度指示器,该表单活动不包含任何列表视图和刷新布局,并且不支持任何滑动手势?

谢谢.

android progress-bar android-styles

10
推荐指数
1
解决办法
6114
查看次数

如何在android主题声明中添加自定义项?

我在styles.xml中有很少的自定义主题
现在每当活动采用主题时,它都使用colorPrimary,colorPrimaryDarkcolorAccent值.
对于我的布局背景我正在使用?attr/colorAccent,因此它可以根据所选主题选择背景颜色.
如果我使用上述任何值,它工作正常.但我想为我的背景颜色定义一个自定义项目值.
我在下面尝试了这个,但它没有奏效.任何使它成功的想法?
我的自定义主题具有自定义值:

<style name = "customTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#4285f4</item>
    <item name="colorPrimaryDark">#2C75F2</item>
    <item name="colorAccent">#E1FFC7</item>
    <item name="customBgColor">#d3d3d3</item>
</style>
Run Code Online (Sandbox Code Playgroud)


我想在布局的风格中使用它

<style name="layoutStyle" >
    <item name="android:background">?attr/customBgColor</item>
</style>
Run Code Online (Sandbox Code Playgroud)

android android-theme android-styles

10
推荐指数
1
解决办法
2895
查看次数

资源 android:attr/android:progressBarStyle 未找到

在将 Android Studio 更新到最新版本后尝试构建项目时,出现此错误。我收到以下错误:

C:\Users\YaCn.gradle\caches\transforms-2\files-2.1\5502c0022567bdcff063e0fb4352b137\folioreader-0.3.3\res\layout\progress_dialog.xml:10: AAPT: 错误/资源栏:androidprogressattr成立。

那个 XML :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/layout_loading"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:gravity="center">
        <ProgressBar android:id="@+id/loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="?android:attr/android:progressBarStyle"/>
        <TextView android:id="@+id/label_loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textSize="18sp"
            android:textColor="@android:color/white"
            android:text="@string/loading"/>
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

构建gradle文件:

   apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.admin.hashtab"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

        manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                onesignal_app_id               : "654bcb8c-90a6-4012-924a-e18e5787a7de",
                                onesignal_google_project_number: "3520309722"]

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles …
Run Code Online (Sandbox Code Playgroud)

android android-progressbar android-xml android-styles

10
推荐指数
2
解决办法
3360
查看次数

Android 5.0 Lollipop:setColorFilter"泄漏"到其他按钮上

setColorFilter用来设置我的一个按钮的彩色滤镜.这一直在Android 5.0 Lollipop更新之前完美运行.现在,滤色器似乎泄漏到我的其他按钮上,即使我关闭活动并重新打开(如果我关闭应用程序并重新打开它会重置).

我的styles.xml(v21):(与旧的相同,除了它的父级是Material,之前是Holo)

<style name="Theme.FullScreen" parent="@android:style/Theme.Material.Light.NoActionBar.Fullscreen">
    <item name="android:buttonStyle">@style/StandardButton</item>
    <item name="android:windowTranslucentStatus">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的styles.xml(适用于所有版本):

<style name="StandardButton" parent="android:style/Widget.Button">
    <item name="android:background">@android:drawable/btn_default</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的按钮:

<Button
    android:id="@+id/mainMenuButton"              
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="mainMenu"
    android:text="@string/button_mainMenu"
    android:visibility="gone" />
Run Code Online (Sandbox Code Playgroud)

我的代码:

Button mainMenuButton = (Button) findViewById(R.id.mainMenuButton);
mainMenuButton.getBackground().setColorFilter(new PorterDuffColorFilter(getResources().getColor(R.color.light_green), PorterDuff.Mode.MULTIPLY));
mainMenuButton.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)

颜色:

<color name="light_green">#5CD65C</color>
Run Code Online (Sandbox Code Playgroud)

结果:

我打开应用程序,然后游戏活动和所有按钮都正确显示.我按下按钮设置滤色器,返回主菜单并重新打开游戏活动,现在所有按钮都是绿色.

有任何想法吗?

android android-layout android-styles android-5.0-lollipop

9
推荐指数
2
解决办法
2648
查看次数

Android默认按钮样式无法正常工作

我正在尝试设置我的样式,使所有按钮成为特定的颜色组合,特别是蓝色和白色文本.这是我的主要styles.xml:

<resources>
    <style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
        <!-- various items -->

        <item name="android:buttonStyle">@style/ButtonStyle</item>
    </style>

    <!-- a couple of other styles -->

    <style name="ButtonStyle" parent="android:style/Widget.Button">
        <item name="android:textSize">19sp</item>
        <item name="android:textColor">@color/primaryTextContrast</item>
        <item name="android:background">@color/primary</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

在清单中:

 <application
        android:name=".CustomApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/application_name"
        android:theme="@style/CustomTheme">
Run Code Online (Sandbox Code Playgroud)

color/primary是深蓝色,color/primaryTextContrast是白色的.在棒棒糖上,按钮看起来很完美.在4.1设备上,它是浅灰色和黑色文本.我发现这样做的每一个资源都与我正在做的完全一样,所以我不知道我在这里缺少什么.

我在基本样式定义中控制文本大小也遇到了类似的问题.

更新:这是颜色.

<resources>
    <color name="primary">#3F51B5</color>
    <color name="dark">#303F9F</color>
    <color name="accent">#FFCA28</color>
    <color name="background">@android:color/white</color>
    <!-- Color for text displayed on top of the primary or dark color -->
    <color name="primaryTextContrast">@android:color/white</color>
    <!-- Color for text displayed on the background color (which I think …
Run Code Online (Sandbox Code Playgroud)

android android-styles

9
推荐指数
1
解决办法
3798
查看次数

Android“?colorPrimary”与“?attr/colorPrimary”?

我找不到任何关于以下差异的信息:

android:textColor="?attr/colorPrimary"
Run Code Online (Sandbox Code Playgroud)

对比

android:textColor="?colorPrimary"
Run Code Online (Sandbox Code Playgroud)

我读过“?attr”表示当前主题中指定的属性值,但没有“attr”它会给出相同的结果(=我的主题中定义的颜色)。它的行为与其他属性相似吗?

例如:

是否android:background="?attr/selectableItemBackground" 等于android:background="?selectableItemBackground"

据说这里有所不同。

非常感谢。

android android-styles android-attributes

9
推荐指数
1
解决办法
1624
查看次数

android:background 在 style.xml 中不起作用

任何人都可以就以下问题提出建议。

我尝试使用具有 drawable(curve_button.xml) 文件的自定义按钮样式。

颜色已经应用并且看起来不错,但它似乎有问题, <item name="android:background">@drawable/curve_button</item>因为它没有应用。

样式文件

 <style name="CustomButton" parent="Widget.AppCompat.Button.Borderless.Colored">
    <item name="colorButtonNormal">@color/book_appointment</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">@drawable/curve_button</item>
  </style> 
Run Code Online (Sandbox Code Playgroud)

曲线按钮.xml

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
  <item>
    <shape android:shape="rectangle">
      <padding
         android:paddingLeft="34dp"
         android:paddingRight="34.4dp"
         android:paddingTop="16dp"
         android:paddingBottom="16dp"
        />
      <corners android:radius="8dip" />          
    </shape>
  </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

按钮布局

<Button
            android:id="@+id/idBookAppontment"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="Book Appointment"
            android:theme="@style/CustomButton"
            android:layout_marginBottom="12dp"
            android:layout_marginTop="6dp"
            android:layout_marginLeft="38dp"
            android:layout_marginRight="37dp"            
            android:inputType="textCapWords"
            android:layout_gravity="bottom"
            local:MvxBind="Typeface StringToFont('Effra_Rg')"
            android:layout_below="@id/providerTabbarHost"
            android:layout_alignParentBottom="true" />
Run Code Online (Sandbox Code Playgroud)

android android-layout android-styles

9
推荐指数
1
解决办法
1933
查看次数