标签: android-styles

如何在Android中以编程方式创建"水平样式"进度条?

我在我的应用程序中以编程方式创建了一个ProgressBar,默认情况下它是SPIN样式但是我希望它以HORIZONTAL样式.我没有看到任何方法/常量来实现这一点.

而且我不想使用ProgressDialog,因为它与我的App UI主题不一致.

有什么建议吗?

android android-progressbar android-styles

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

TextView的样式和android:textAppearance属性有什么区别?

如果我将我定义TextView为:

 <TextView
        style="@android:style/TextAppearance.DeviceDefault.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
Run Code Online (Sandbox Code Playgroud)

它与做的基本相同:

 <TextView
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
Run Code Online (Sandbox Code Playgroud)

我知道这style是一种更宽泛的限定符(即不能设置所有属性android:textAppearance)但是它提出了一个问题:为什么要打扰?使用android:textAppearance结束有什么好处style吗?

android textview android-styles

26
推荐指数
4
解决办法
3638
查看次数

ResourcesCompat.getDrawable()vs AppCompatResources.getDrawable()

我对这两个API有点困惑.

ResourcesCompat.getDrawable(Resources res,int id,Resources.Theme theme)

返回与特定资源ID关联的可绘制对象,并为指定的主题设置样式.将根据底层资源返回各种类型的对象 - 例如,纯色,PNG图像,可缩放图像等.

在API级别21之前,不会应用主题,此方法只需调用getDrawable(int).

AppCompatResources.getDrawable(Context context,int resId)

返回与特定资源ID关联的可绘制对象.

此方法支持在没有平台支持的设备上对矢量动画矢量资源进行充气.

  1. 这两个类之间有什么显着差异(除了矢量膨胀)?
  2. 我应该选择哪一个?为什么?

java android android-theme android-resources android-styles

26
推荐指数
3
解决办法
8226
查看次数

为什么ProgressDialog的背景没有设置为透明?

我想将背景设置为透明,所以我已经设置了以下代码

styles.xml
<style name="dialog" parent="@android:style/Theme.Dialog">  
            <item name="android:windowFrame">@null</item>  
            <item name="android:windowIsFloating">true</item>  
            <item name="android:windowContentOverlay">@null</item>  
            <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>  
            <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>  
            <item name="android:windowBackground">@android:color/transparent</item>  
            <item name="android:windowNoTitle">true</item> 
        </style> 
Run Code Online (Sandbox Code Playgroud)

我有使用Progressdialog类似下面的代码JAVA filefragment.

Activity activity = getActivity() ;
mProgressDialog = new ProgressDialog(activity,R.style.dialog) ;
mProgressDialog.setCancelable(false) ;
mProgressDialog.show() ;
Run Code Online (Sandbox Code Playgroud)

但是我得到了如下图所示的进展,并且它没有透明的背景.

在此输入图像描述

为什么背景不会变为透明?

android progressdialog android-styles

24
推荐指数
3
解决办法
3万
查看次数

在Android Studio 1.0之后,values-21,values-22或values-xx文件夹消失了

当我创建一个API14最小的新项目时,我的项目中没有values-21values-22文件夹.我在任何地方都没有看到任何styles.XML,那么我应该如何为Lollipop输入XML代码呢?

我使用的是Android Studio 1.0.1,我安装了SDK 21,21.1.1,24.0.2.

java android android-studio android-styles

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

Android Studio:如何快速将样式从layout.xml移动到style.xml?

代码块1:我在view.xml中有以下代码

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="monospace"
    android:text="@string/hello" />
Run Code Online (Sandbox Code Playgroud)

代码块2:现在我想把它移到像这样的样式.

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />
Run Code Online (Sandbox Code Playgroud)

代码块3:在我的styles.xml文件中,我希望有这个.

<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

<item name="XXX"/>标记中包装所有这些属性是一个非常手动和烦人的过程.Android Studio是否具有某种类型的魔法来自动将代码块1中的属性转换为代码块3中的项目标记?

xml android android-layout android-studio android-styles

24
推荐指数
1
解决办法
3690
查看次数

更改Android应用的样式和主题中的文本外观

我正在写一个Android应用程序,我想改变我的应用程序的主题.

我已经设法通过使用主题来改变应用程序的背景颜色,但我正在努力改变默认的文本外观.

这是我的styles.xml资源文件.

<resources>
    <style name="QTheme" parent="android:Theme.Light">
        <item name="android:windowBackground">@color/q_green</item>
        <item name="android:colorBackground">@color/q_green</item>
        <item name="android:textAppearance">@style/QText</item> 
    </style>

    <color name="q_green">#008000</color>
    <color name="white">#FFFFFF</color>

    <style name="QText" parent="@android:style/TextAppearance.Medium"> 
        <item name="android:textSize">20sp</item> 
        <item name="android:textColor">@color/white</item> 
        <item name="android:textStyle">bold</item>
        <item name="android:textFont">Verdana</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

并且只是为了检查,这是我的一个TextViews的例子我想在我的布局文件中使用上面的样式.

<TextView
    android:id="@+id/txtDevice"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/device" 
/>
Run Code Online (Sandbox Code Playgroud)

任何人都可以看到我错在哪里?

java android text android-theme android-styles

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

如何以编程方式创建Android主题样式?

有很多关于通过XML创建或自定义Android主题样式的文档和教程,但是还没有找到在代码中创建它的方法.关于如何在代码而不是xml中创建样式的任何想法?

这是示例XML,需要在代码中以编程方式创建:

<resources>
  <style name="AppTheme" parent="android:Theme.Material">
    <item name="android:colorPrimary">@color/primary</item>
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <item name="android:colorAccent">@color/accent</item>
  </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

android android-styles

23
推荐指数
2
解决办法
7903
查看次数

从 Android Studio 4.1 开始,Android 背景可绘制对象在按钮中不起作用

我发现从 Android Studio 4.1 开始,我无法Button通过在 a 上设置颜色来更改 a 的背景颜色android:background,只是没有效果。自定义Drawable也不起作用。

我的背景Drawable

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke
        android:width="1.5dp"
        android:color="@android:color/black" />

    <solid
        android:color="@android:color/white" />

    <corners
        android:radius="8dp" />

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

我的Button

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add To Cart"
    android:background="@drawable/background3"/>
Run Code Online (Sandbox Code Playgroud)

结果:

在此处输入图片说明

android android-button android-drawable android-styles material-design

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

设计FacebookActivity以避免可怕的进度吧

我刚刚使用他们的SDK结合使用Facebook实现了登录ParseFacebookUtilsV4.

在我的清单中FacebookActivity,当我尝试登录时,我必须声明一个启动,这很有效.

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:label="@string/app_name" />
Run Code Online (Sandbox Code Playgroud)

这个片段来自官方文档,所以我没有选择任何东西.我发现它的造型真的很奇怪.在我的模拟器(API 22)上它有一个似乎来自90年代的ProgressBar!有没有办法造型呢?我尝试过更改android:theme属性,但没有成功.

在此输入图像描述

我想扩展com.facebook.FacebookActivity,但在挖掘源代码后我发现它膨胀了一个com.facebook.LoginFragment,然后实际上负责进度条.有任何想法吗?

android facebook android-facebook android-styles

22
推荐指数
1
解决办法
1346
查看次数