我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)
结果:
我打开应用程序,然后游戏活动和所有按钮都正确显示.我按下按钮设置滤色器,返回主菜单并重新打开游戏活动,现在所有按钮都是绿色.
有任何想法吗?
我正在尝试设置我的样式,使所有按钮成为特定的颜色组合,特别是蓝色和白色文本.这是我的主要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中正确布局组件.我是一名经验丰富的CSS/MXML开发人员,我很难完全理解Android组件中的布局属性.
有一点是我不确定这些之间的区别:
你应该使用线性,表格或相对布局来使用其中一个吗?我想学习的一个例子是布局上的整体边距,其中包含与屏幕顶部/中部/底部相关的独立组件.sdk文档是一个良好的开端,但它们并没有显示在不同情况下的工作方式.
关于在哪里学习更复杂/全面的布局设计的任何提示?
我正在寻找一个看起来像的textview
.我用下面的代码来实现这个..
SpannableString text;
text = new SpannableString(bal_dollars.getText());
int index = bal_dollars.getText().toString().indexOf(".");
text.setSpan(new TextAppearanceSpan(getApplicationContext(),
R.style.HeroGraphicBalanceSmallFont), index, bal_dollars
.getText().toString().length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
bal_dollars.setText(text, TextView.BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)
这是跨度中使用的样式..
<style name="HeroGraphicBalanceSmallFont" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_width">wrap_content</item>
<item name="android:textSize">50sp</item>
<item name="android:singleLine">true</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">top|right</item>
<item name="android:paddingBottom">30dp</item>
<item name="android:gravity">top|right</item>
<item name="android:textColor">@color/status_text</item>
<item name="customFont">fonts/HeroicCondensedMedium.ttf</item>
</style>
Run Code Online (Sandbox Code Playgroud)
一切看起来都很好,除了目标文本跨度的间距,即小数部分重力.
.我尝试了所有的xml属性.请帮忙
关于homeAsUpIndicator有很多问题,我尝试了所有没有结果的问题.
代码很简单.我只有Android Studio 1.0.1的默认NavigationDrawer代码,appcompat和SDK21构建.
我想改变de homeAsUpIndicator,但只有以编程方式工作:
actionBar.setHomeAsUpIndicator(R.drawable.custom_indicator);
Run Code Online (Sandbox Code Playgroud)
当我尝试将其移动到styles.xml时,它不起作用:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="android:homeAsUpIndicator">@drawable/custom_indicator</item>
<item name="homeAsUpIndicator">@drawable/custom_indicator</item>
</style>
Run Code Online (Sandbox Code Playgroud)
颜色正确应用,但不是homeAsUpIndicator.我能尝试什么?这是默认项目,我尝试了两个看似无处不在的简单解决方案.Java语句只是一种解决方法,因为我认为最好放在styles.xml上.可能发生什么?默认项目是否覆盖了我的风格?
绿色来自哪里?我已经尝试更改accentColor属性,该属性适用于应用程序的其他部分,但不在此处.
来自Lollipop的应用程序的屏幕截图.
我怎样才能改变颜色:
也许是未来的一些提示......你是怎么发现的?我一直在遇到所有这些令人困惑的颜色/造型问题.是否有某种列表告诉我,我需要为某个组件覆盖哪个默认颜色或属性?
我正在尝试像这样自定义我的搜索栏:
在API级别<23时,即使seekbar的进度等于0,也可以看到进度线.但是在API级别= 23时,我有一个奇怪的问题:进度线在相同的条件下没有显示= /我想看到这一行,因为它澄清使用我的搜索栏的边界.
我的seek_bar_progress_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/seek_bar_track" />
<item android:id="@android:id/secondaryProgress">
<scale
android:drawable="@drawable/seek_bar_track"
android:scaleWidth="100%" />
</item>
<item android:id="@android:id/progress">
<scale
android:drawable="@drawable/seek_bar_track"
android:scaleWidth="100%" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我的style.xml:
<style name="seek_bar_style" parent="android:Widget.Holo.Light.SeekBar">
<item name="android:progressDrawable">@drawable/seek_bar_progress_bar</item>
<item name="android:indeterminateDrawable">@drawable/seek_bar_progress_bar</item>
<item name="android:thumb">@drawable/seek_bar_thumb_selector</item>
</style>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我想EditText在长按时更改弹出上下文菜单背景EditText.
我尝试了以下代码,但它不起作用.弹出上下文菜单背景仍未更改.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="dialogTheme">@style/MyDialogTheme</item>
<item name="popupMenuStyle">@style/MyPopupStyle</item>
</style>
<style name="MyPopupStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@color/colorAccent</item>
</style>
<style name="MyDialogTheme" parent="Base.V7.Theme.AppCompat.Dialog">
<item name="android:colorBackground">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我想要的结果是,弹出上下文菜单背景与品红色的强调色相同.我怎样才能实现它?
android contextmenu android-theme android-support-library android-styles
我的seekBar样式是android Widget.AppCompat.SeekBar.Discrete.我有自己的tickMarker,但你可以看到它显示在拇指标记前面,但我不想看到拇指背后的蜱虫.
而我拥有的东西:
我的XML:
<android.support.v7.widget.AppCompatSeekBar
style="@style/seekbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="4"
android:padding="4dp"
android:progress="0"/>
Run Code Online (Sandbox Code Playgroud)
我的风格:
<style name="seekbarStyle" parent="Widget.AppCompat.SeekBar.Discrete">
<item name="tickMark">@drawable/seekbar_tickmark</item>
<item name="android:thumb">@drawable/circle</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我想更改活动切换按钮的颜色。但仅仅改变rippleColor 就会产生影响。我希望自定义活动按钮的背景颜色和文本颜色。
<style name="ToggleButtonGroupStyle" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="rippleColor">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
在下面的toggleButtonGroup中,我使用了上面的这种样式:
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/priority_btn_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentLeft="true"
app:selectionRequired="true"
app:singleSelection="true"
app:checkedButton="@+id/btn_one"
>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_one"
style="@style/ToggleButtonGroupStyle"
android:layout_width="@dimen/priority_btn_width"
android:layout_height="wrap_content"
android:shadowColor="@color/project_text"
android:text="0" />
<com.google.android.material.button.MaterialButton
style="@style/ToggleButtonGroupStyle"
android:layout_width="@dimen/priority_btn_width"
android:layout_height="wrap_content"
android:text="!" />
<com.google.android.material.button.MaterialButton
style="@style/ToggleButtonGroupStyle"
android:layout_width="@dimen/priority_btn_width"
android:layout_height="wrap_content"
android:text="!!" />
<com.google.android.material.button.MaterialButton
style="@style/ToggleButtonGroupStyle"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="!!!" />
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)
有人能给我提示一下这里的问题是什么吗?谢谢 :)
android android-theme android-button android-styles material-components-android