我想做个自定义Dialog.因为我不喜欢它的风格,我想要圆角矩形而不是尖角.我知道如何通过主题实现它AndroidManifest.xml,例如,我使用:
android:theme="@style/Theme.CustomDialog"
Run Code Online (Sandbox Code Playgroud)
而且Theme.CustomDialog.xml:
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/filled_box</item>
<item name="android:windowNoTitle">true</item>
filled_box.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="30dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
如何通过扩展Dialog或AlertDialog?来实现类似的结果?
我想更改android偏好片段中的文本颜色.我目前正在使用自定义主题来更改复选框图像,背景,onClick突出显示,这一切都很有效...除了文本颜色.我不想使用默认主题,我想拥有自己的主题,所以它看起来我想要的只是改变文本颜色,有人可以帮助.
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="selectedTextStyle">
<item name="android:textSize">18sp</item>
</style>
<style name="buttonTextStyle">
<item name="android:textSize">20sp</item>
</style>
<style name="PreferencesTheme" >
<item name="android:windowBackground">@drawable/lists_background</item>
<item name="android:listViewStyle">@style/listViewPrefs</item>
<item name="android:checkboxStyle">@style/MyCheckbox</item>
</style>
<style name="MyTextAppearance" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/black</item>
</style>
<style name="listViewPrefs" parent="@android:Widget.ListView">
<item name="android:listSelector">@layout/list_selector_master</item>
<item name="android:textAppearance">@style/MyTextAppearance</item>
</style>
<style name="MyCheckbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/btn_check</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
表现:
<activity
android:name="com.package.SettingsActivity"
android:theme="@style/PreferencesTheme"
android:configChanges="keyboard|orientation" >
</activity>
Run Code Online (Sandbox Code Playgroud)
活动:
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as …Run Code Online (Sandbox Code Playgroud) 我想将自定义样式应用于SwitchCompat.更改可打开和关闭状态的drawable和文本.我怎样才能做到这一点?我找不到任何关于如何做到这一点的例子.我在styles.xml中尝试了以下内容,但显然我没有使用正确的父:
<style name="Switch" parent="android:Widget.AppCompat.Widget.CompoundButton.SwitchCompat">
<item name="android:textOn">@string/common_yes</item>
<item name="android:textOff">@string/common_no</item>
<item name="android:thumb">@drawable/btn_switch_selector</item>
<item name="android:track">@drawable/btn_switch_bg_selector</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑
我设法在代码中更改drawables.
switchView.setThumbResource(R.drawable.btn_switch_selector);
switchView.setTrackResource(R.drawable.btn_switch_bg_selector);
Run Code Online (Sandbox Code Playgroud)
但我还没有找到改变开关文本的方法.以下代码段似乎不起作用.也许我需要设置更多的文本属性?
switchView.setTextOn(context.getString(R.string.common_yes));
switchView.setTextOff(context.getString(R.string.common_no));
Run Code Online (Sandbox Code Playgroud)
根据SwitchCompat源代码,应支持开/关文本:https: //android.googlesource.com/platform/frameworks/support/+/421d8baa4a524e1384bcf033360bccaf8d55081d/v7/appcompat/src/android/support/v7/widget/ SwitchCompat.java
{@link #setText(CharSequence)text}属性控制切换标签中显示的文本,而{@link #setTextOff(CharSequence)off}和{@link #setTextOn(CharSequence)on}文本控制文本在拇指上.
编辑2
终于找到了代码解决方案.显然setShowText()需要设置true为文本显示在开关上.
switchView.setTextOn(context.getString(R.string.common_yes));
switchView.setTextOff(context.getString(R.string.common_no));
switchView.setShowText(true);
switchView.setThumbResource(R.drawable.btn_switch_selector);
switchView.setTrackResource(R.drawable.btn_switch_bg_selector);
Run Code Online (Sandbox Code Playgroud)
和xml解决方案
<android.support.v7.widget.SwitchCompat
android:id="@+id/view_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:thumb="@drawable/btn_switch_selector"
app:track="@drawable/btn_switch_bg_selector"
android:textOn="@string/common_yes"
android:textOff="@string/common_no"
app:showText="true" />
Run Code Online (Sandbox Code Playgroud)
我还是想知道是否有办法把它放进去styles.xml.
我开始在我的应用程序上实现暗模式,我正在使用Theme.AppCompat.DayNight.NoActionBar. 设备上一切正常,但我想查看 Android Studio 上的差异,因此我不必继续运行代码来查看更改。
如何切换 Android Studio Preview 以显示夜间模式与灯光模式主题?
谢谢。
编辑:为了清楚起见,我想在预览中显示资源文件夹-night而不是普通资源文件夹中的任何内容。
android android-theme android-studio material-design android-darkmode
我很确定这个问题已经在某个地方得到了回答.这似乎太常见了.但我找不到答案.我也不能找出解决方案.
这是问题所在:
我希望我的一个TableRow具有不同的背景颜色.这很简单,我只需要添加
android:background="#123456"
Run Code Online (Sandbox Code Playgroud)
在TableRow的XML声明中.但是,我也希望我的应用程序有两个主题.在另一个主题中,TableRow应该具有不同的背景颜色.我找不到在主题中定义颜色值并使用它的方法.我想输入这样的东西:
<style name="Theme.MyApp" parent="@style/Theme.Light">
<color "my_cool_color">#123456</color>
</style>
<style name="Theme.MyApp.Dark" parent="@style/Theme.Dark">
<color "my_cool_color">#654321</color>
</style>
Run Code Online (Sandbox Code Playgroud)
并且,在TableRow的声明中:
android:background="@color/my_cool_color"
Run Code Online (Sandbox Code Playgroud)
因此,当我更改主题时,TableRow的背景颜色也会发生变化.我已经尝试了很多个小时并且没有成功......我没有尝试的一件事是基于TableRow创建我自己的小部件并为它声明一个单独的样式 - 我认为这应该有用,但它是对于这么简单的问题来说,这太重了
我确信有一个简单的答案,但我无法找到它所以我把它扔进stackoverflow ...... ;-)
我将把它作为一个例子.我有一个Android应用程序,用户可以在首选项中选择主题 - 深色或浅色主题.根据所选主题,我必须在我的应用程序中调整20种颜色.所以我希望我可以在主题中定义颜色,然后在我的TextViews等中使用这些如此定义的颜色的名称.但到目前为止,我无法弄清楚如何做到这一点,在这里和那里找不到任何解决方案.我真的不想为这20种颜色中的每种颜色定义一个额外的黑暗和浅色样式,但到目前为止这似乎是我能找到的唯一解决方案.
非常感谢任何提示
马丁:
更新:
在伪语法中,这就是我正在寻找的.可能吗?
<style name="AppTheme.MyDark" parent="android:Theme">
-?-> titleColor = "#ffffff"
-?-> introColor = "#ffaaaa"
</style>
<style name="AppTheme.MyLight" parent="android:Theme.Light">
-?-> titleColor = "#000000"
-?-> introColor = "#004444"
</style>
<TextView
android:id="@+id/quoteTitle"
android:textColor=@titleColor
...
</TextView>
<TextView
android:id="@+id/quoteIntro"
android:textColor=@introColor
...
</TextView>
Run Code Online (Sandbox Code Playgroud) 我想更改我的应用程序中的所有颜色文本.所以我编写了这段代码,并在清单中设置了我的主题:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但只有TextView文本为白色.我希望Button和EditText也是白色的.
谁能帮我?先感谢您.
android colors android-theme android-edittext android-button
所以我用Holo Colors Generator和Action Bar Style Generator将Holo Theme的风格改为我自己的颜色.但是当我在编辑文本中选择文本时,所选位置的"标记"仍为蓝色.我该怎么改变它?



我面临着问题.我试图让我的应用程序中的编辑文本在主题的帮助下看起来一样.
我已经在在线工具(9-patch图像)的帮助下生成了样式,并尝试在我的主题中设置它
<!-- Base application theme. -->
<style name="DefaultAppTheme" parent="Theme.AppCompat">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">@color/blue</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">@color/darkblue</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">@color/cornflowerblue</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:editTextStyle">@style/EditTextDefault</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的编辑文本样式
<style name="EditTextDefault" parent="android:Widget.EditText">
<item name="android:background">@drawable/edit_text_holo_light</item>
<item name="android:textColor">@color/light_blue</item>
<item name="android:layout_marginLeft">@dimen/margin_edit_text_default</item>
<item name="android:layout_marginRight">@dimen/margin_edit_text_default</item>
<item name="android:layout_marginTop">@dimen/margin_edit_text_default</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是,如果使用编辑文本而不为每个编辑文本手动指定样式,则此操作无效.
这不起作用
<EditText
android:id="@+id/edit_text_login"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我在delphi下,我使用android框架创建一个编辑.当我将主题设置为Theme.DeviceDefault.Light.NoActionBar然后我可以在我的EditText中选择一些文本,我有一个弹出窗口"select all/cut/copy/paste/etc",如下图所示.
但是,当我选择Theme.Material.Light.NoActionBar或Theme.Holo.Light.NoActionBar然后我无法选择我的EditText中的任何文本(我没有右或左文本选择句柄),当然我没有任何复制/粘贴弹出窗口
他们是否可以在Theme_Material_Light_NoActionBar上进行此复制/粘贴弹出?
Theme.DeviceDefault.Light.NoActionBar
Theme_Material_Light_NoActionBar
注1:
当我将屏幕移动到水平然后编辑文本占用所有可用空间,然后我可以看到我的左右文本选择句柄,如下图所示,但我认为这是因为主题交换到Theme.DeviceDefault.Light.NoActionBar当我将屏幕移动到水平但我不确定:
注2:
在我的editText上,当我执行setCustomSelectionActionModeCallback(new Callback(){})时,从不调用Callback :(这是不正常的我认为?editText中的哪些内容可以禁止回调?
注2:
我可以在所有主题中选择文本(但我不能将其复制出去),但除了在Theme.DeviceDefault.Light.NoActionBar中,我看不到左右文本选择句柄.
注3:
Theme.DeviceDefault.Light.NoActionBar仅在某些手机上显示左右文本选择句柄,如三星星系.在其他方面它没有用.
注4:
我发现了部分问题的根源!这是因为我通过WindowManager.addView(view,layout_params)创建我的视图,这样startactionmodeforChild返回null,这禁止动作栏和文本选择句柄显示.现在如果我在我的edittext中做了类似的事情:
@Override
public ActionMode startActionMode(ActionMode.Callback callback) {
Activity host = (Activity) this.getContext();
return host.getWindow().getDecorView().startActionMode(callback);
}
Run Code Online (Sandbox Code Playgroud)
然后我可以看到左右文本动作句柄(但不是棉花糖,它只在棒棒糖上工作,我不知道为什么).我现在的问题是显示了操作栏,但它显示为空:(内部没有任何内容(但我可以看到剪切/复制/过去控件位于转储视图中的内部).所以现在我不寻找方法通过弹出菜单替换此操作栏(如图片Theme.DeviceDefault.Light.NoActionBar).任何想法?
android textview android-theme android-edittext android-styles