我正在尝试为我的警报对话框设置android Theme.Light主题,但到目前为止没有成功.在阅读了一些教程后,我使用AlertDialog.Builder收集了这些教程,我们无法直接在构造函数中设置主题(至少在API级别7中).
我找到的替代解决方案是使用ContextThemeWrapper,每个人都保证会解决我的问题.所以我编写了这样的代码:
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(context, R.style.popup_theme));
Run Code Online (Sandbox Code Playgroud)
我在values文件夹中描述了我的主题:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="back_color">#ffffffff</color>
<style name="popup_theme" parent="@android:style/Theme.Light">
<item name="android:windowBackground">@color/back_color</item>
<item name="android:colorBackground">@color/back_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
不幸的是,我仍然得到默认的Theme.Dialog.Alert主题.谁能告诉我为什么?我哪里错了?
编辑:如果您不知道我的问题的答案,请投票.我有一个坏习惯,发布被卡住的问题:(
我需要制作一个活动,以便活动保持全屏(没有标题栏),但操作栏出现.
App使用Holo Light作为其界面.
有这样的风格/主题吗?
在res/values-v11/styles.xml,我无法使用,Theme.Holo.Light.NoActionBar因为它是在API级别13中添加的.我可以使用Theme.Light.NoTitleBar,而没有视觉差异吗?据我所知,他们应该都有白色背景,状态和导航栏,没有别的.
我对这两个API有点困惑.
ResourcesCompat.getDrawable(Resources res,int id,Resources.Theme theme)
返回与特定资源ID关联的可绘制对象,并为指定的主题设置样式.将根据底层资源返回各种类型的对象 - 例如,纯色,PNG图像,可缩放图像等.
在API级别21之前,不会应用主题,此方法只需调用getDrawable(int).
AppCompatResources.getDrawable(Context context,int resId)
返回与特定资源ID关联的可绘制对象.
此方法支持在没有平台支持的设备上对矢量和动画矢量资源进行充气.
我正在为Android 2.2及更高版本开发应用程序.我使用伟大的ActionBarSherlock(谢谢你,Jake Wharton !!)来使用预ICS设备上的操作栏.
虽然动作栏看起来很棒,但所有其他gui元素都具有设备默认主题的外观(在我的例子中为HTC Sense 3).
是否有可能使用Holo.Dark.Theme在所有Android设备上设置我的(> = Android 2.2)应用程序样式?
我用Android 4.0.3编译我的应用程序,minSDK版本是8.
我正在尝试使用SherlockActionBar实现ViewPagerIndicator.它的工作原理:我可以滑动碎片,但风格不起作用!
它看起来像这样:
相关主题:https://github.com/JakeWharton/Android-ViewPagerIndicator/issues/66
我知道出了什么问题:在VPI的示例中,页面的样式在AndroidManifest.xml中设置(例如)
<activity
android:name=".SampleTabsDefault"
android:theme="@style/Theme.PageIndicatorDefaults">
</activity>
Run Code Online (Sandbox Code Playgroud)
但是当我将android:theme元素添加到我自己的Manifest.xml中时,我得到以下异常:
03-16 11:06:24.400: E/AndroidRuntime(483): Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
Run Code Online (Sandbox Code Playgroud)
我还尝试将所有样式信息复制到styles.xml,但这也不起作用.
你能告诉我如何设置VPI的风格吗?谢谢!
编辑:现在我已经添加了
<activity
android:name=".SampleTabsDefault"
android:theme="@style/StyledIndicators">
</activity>
Run Code Online (Sandbox Code Playgroud)
到我的Manifest.xml
以及styles.xml中的以下样式
<style name="Theme.BataApp" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>
<style name="StyledIndicators" parent="Theme.BataApp">
<item name="vpiTitlePageIndicatorStyle">@style/Widget.TitlePageIndicator</item>
<item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>
<item name="vpiTabTextStyle">@style/Widget.TabPageIndicator.Text</item>
</style>
Run Code Online (Sandbox Code Playgroud)
结果:我没有得到任何异常,看到样式,但我现在看不到任何碎片:(
活动代码可以在这里找到:http://pastebin.com/hsNgxFDZ 当前页面的风格截图:
我正在使用Lollipop设备(MotoG 2014),我读到了进度条着色,但这不起作用......我得到了默认的进度条颜色.我在这里错过了什么?
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="50dp"
android:layout_height="50dp"
android:backgroundTintMode="src_in"
android:indeterminate="true"
android:indeterminateTint="#f00" />
Run Code Online (Sandbox Code Playgroud)
非常感谢.
android android-layout android-theme material-design android-5.0-lollipop
我正在写一个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)
任何人都可以看到我错在哪里?
我在这里遇到了问题.我刚刚从sdk 22更新到23,并且不推荐使用以前版本的"getColorStateList()".
我的代码是这样的
seekBar.setProgressTintList(getResources().getColorStateList(R.color.bar_green));
valorslide.setTextColor(getResources().getColorStateList(R.color.text_green));
Run Code Online (Sandbox Code Playgroud)
较旧的"getColorStateList"是
getColorStateList(int id)
Run Code Online (Sandbox Code Playgroud)
新的是
getColorStateList(int id, Resources.Theme theme)
Run Code Online (Sandbox Code Playgroud)
我如何使用Theme变量?提前致谢
我正在研究一个关于支持库和工具栏的示例,这是Android文档中布局的代码
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
Run Code Online (Sandbox Code Playgroud)
这是我第一次看到这些?attr,我不知道它们的含义或存储这些值的位置.这些是自定义还是在Android框架上预定义的?
参考:Android工具栏文档
android android-layout android-theme android-support-library material-design