我有一个Activity包含EditText3.1的.根据用户输入,我更改EditText中的文本颜色(红色表示错误),然后在文本正常时将其重置为黑色.
一个问题涉及改变活动的整体主题.例如,将其更改为浅色主题的常规黑暗主题会导致黑色文本显示在黑色背景下 - 因此我需要进入并更改代码,而不是在数据正常时将文本重置为白色.
如果我将主题更改为Activity,而不是必须更改此代码,我想知道是否有办法以编程方式为给定主题提取默认的EditText文本颜色,然后我可以将文本切换回默认颜色而不是在白色,黑色等硬编码
在我的一个活动中,我的EditText视图过去看起来像这样

但现在他们看起来像这样

我需要帮助改变它:从矩形到下划线.
背景
因为我需要创建一个自定义ActionBar,所以我必须YesterdayActivity使用以下内容更改相关活动的主题
样式:
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">40dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
Run Code Online (Sandbox Code Playgroud)
表现:
<activity
android:name="com.example.YesterdayActivity"
android:theme="@style/CustomTheme">
</activity>
Run Code Online (Sandbox Code Playgroud)
的onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_yesterday);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.yesterday_title_bar);
…
}
Run Code Online (Sandbox Code Playgroud) 在构建我的应用程序时,我开始使用Theme.Light.NoTitleBar.Fullscreen主题.我为这样的整个应用程序构建了所有布局,并让我看到了我想要的东西.布局中使用的一些drawable的大小是专门设置的,而其他的则设置为wrap_content.
然后我决定切换到Holo灯光主题.当我这样做时,设置为wrap_content的布局中使用的所有drawable最终都会变大.几乎就像他们从一个更大的水桶中拉出来一样.事实上,有些人看起来已经被拉长了.


我知道旧主题中的背景是黑色的,但这不是问题(这实际上是包含在另一个布局中的布局文件).显然两者之间的规模差异很大.
在我的活动中,我正在维护一个SuperActivity,我正在设置主题.
public class SuperActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyTheme);
}
}
Run Code Online (Sandbox Code Playgroud)
的themes.xml
<!-- ImageBackround -->
<style name="Theme.MyTheme" parent="ThemeLight">
<item name="myBgColor">@color/translucent_black</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在我想在我的一个孩子活动中获取这种颜色.
正如在这个可能的答案中所提到的,我写道:
int[] attrs = new int[] { R.attr.myBgColor /* index 0 */};
TypedArray ta = ChildActivity.this.obtainStyledAttributes(attrs);
int color = ta.getColor(0, android.R.color.background_light);
String c = getString(color);
ta.recycle();
Run Code Online (Sandbox Code Playgroud)
但每次我得到的默认值为android.R.color.background_light&而不是R.attr.myBgColor.
哪里我做错了.我是否传递了错误的背景ChildActivity.this?
在我正在构建的这个应用程序中,我在我的活动中添加了一个导航抽屉片段.我使用5.0,所以我已经能够设置primaryColor和primaryColorDark以获得正确的颜色.我决定尝试将我的Nav Drawer设计为与5.0中的Google Now抽屉非常相似,其中Nav Drawer拥有自己的状态栏背景.(不能张贴图片,信誉不够>.>)
我在这里已经按照这个问题提出了建议,这有很大帮助.当我把它拉出来时,我已经在状态栏下绘制了我的导航抽屉.唯一的麻烦是,我无法弄清楚如何设置抽屉中显示的状态栏的颜色.目前,它只显示白色.
以下是我的样式和代码的相关部分:
活动布局:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main"
android:fitsSystemWindows="true">
<!-- main content -->
...
<!-- Drawer fragment -->
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:theme="@style/DrawerTheme"
android:fitsSystemWindows="true"
android:choiceMode="singleChoice"
android:name="com.myname.appname.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
片段布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/navDrawerFragment"
android:theme="@style/DrawerTheme"
android:background="@color/WindowBackground"
tools:context=".NavigationDrawerFragment"
android:fitsSystemWindows="true">
<!-- content here -->
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
上面的每个链接,为活动设置状态栏的颜色(此部分正常工作):
public void onCreate(Bundled savedInstanceState) {
super.onCreate(savedInstanceState);
// ....
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
// ....
}
Run Code Online (Sandbox Code Playgroud)
最后,我为活动创建了相关的样式,以及我试图分配给片段的样式.
<style name="StatusBarActivityTheme" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-theme navigation-drawer android-5.0-lollipop
使用AppCompatActivity,您必须扩展AppCompat主题.
您可以自定义的完整属性列表是什么,它们的默认值是多少?
我已经收集了一份我已经找到但却不知道是否完整的清单
帮我完成它
<style name="Theme.Custom.AppCompat" parent="Theme.AppCompat">
<item name="colorAccent">@color/accent_material_dark</item>
<item name="colorButtonNormal">@color/button_material_dark</item>
<item name="colorControlActivated">?attr/colorAccent</item>
<item name="colorControlHighlight">@color/ripple_material_dark</item>
<item name="colorControlNormal">?android:attr/textColorSecondary</item>
<item name="colorPrimary">@color/primary_material_dark</item>
<item name="colorPrimaryDark">@color/primary_dark_material_dark</item>
<item name="colorSwitchThumbNormal">@color/switch_thumb_material_dark</item>
<item name="controlBackground">?attr/selectableItemBackgroundBorderless</item>
<item name="android:colorBackground">@color/background_material_dark</item>
<item name="android:colorForeground">@color/foreground_material_dark</item>
<item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
<item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item>
<item name="android:textColorSecondary">@color/abc_secondary_text_material_dark</item>
<item name="android:textColorSecondaryInverse">@color/abc_secondary_text_material_light</item>
<item name="android:windowBackground">@color/background_material_dark</item>
</style>
<style name="Theme.Custom.AppCompat.Light" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/accent_material_light</item>
<item name="colorButtonNormal">@color/button_material_light</item>
<item name="colorControlActivated">?attr/colorAccent</item>
<item name="colorControlHighlight">@color/ripple_material_light</item>
<item name="colorControlNormal">?android:attr/textColorSecondary</item>
<item name="colorPrimary">@color/primary_material_light</item>
<item name="colorPrimaryDark">@color/primary_dark_material_light</item>
<item name="colorSwitchThumbNormal">@color/button_material_light</item>
<item name="controlBackground">?attr/selectableItemBackgroundBorderless</item>
<item name="android:colorBackground">@color/background_material_light</item>
<item name="android:colorForeground">@color/foreground_material_light</item>
<item name="android:textColorPrimary">@color/abc_primary_text_material_light</item>
<item name="android:textColorPrimaryInverse">@color/abc_primary_text_material_light</item>
<item name="android:textColorSecondary">@color/abc_secondary_text_material_light</item>
<item name="android:textColorSecondaryInverse">@color/abc_secondary_text_material_light</item>
<item name="android:windowBackground">@color/background_material_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)
此外,在Android中创建自定义AppCompat主题的最佳方法是什么?
我们的应用程序依赖于让我们从和AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)中选取浅色和深色主题颜色values/colorsvalues-night/colors
但是每次我们尝试使用 时WebView,它都会从重置 UiMode 开始,并且我们的应用程序会混淆为我们的主题选择哪些颜色值
有人遇到类似的问题吗?
我想更改活动切换按钮的颜色。但仅仅改变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
在我这样res/font定义:font-family
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font app:fontStyle="normal" app:fontWeight="400" app:font="xyz_1"/>
<font app:fontStyle="normal" app:fontWeight="500" app:font="xyz_2"/>
</font-family>
Run Code Online (Sandbox Code Playgroud)
如何将其加载到 Jetpack Compose 中并将其用作FontFamily对象?
我是一名 Android 初学者,正在开始使用 Jetpack Compose。我对新 Compose 项目模板创建的这两个设置文件感到困惑:themes.xmlvsTheme.kt和colors.xmlvs Color.kt。和colors.xml都Color.kt包含颜色定义,并且 和 都themes.xml包含Theme.kt原色定义。
XML 文件和 Kotlin 文件有什么区别?我应该手动同步他们的内容吗?