我想在用户点击按钮时将我的应用程序中的屏幕布局更改为全屏但是它不起作用,我的代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFullScreen = (Button) findViewById(R.id.btnFullScreen);
btnNormalScreen = (Button) findViewById(R.id.btnNormalScreen);
btnFullScreen.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setTheme(R.style.AppBaseThemeFullScreen);
}
});
btnNormalScreen.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setTheme(R.style.AppBaseTheme);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的全屏主题是:
<style name="AppBaseThemeFullScreen" parent="android:Theme.Light">
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的师范主题是
<style name="AppBaseTheme" parent="android:Theme.Light">
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
所以,如果有任何方法可以帮助我.
我正在尝试在我的项目中使用ActionBarActivity.我已按照https://developer.android.com/tools/support-library/setup.html#中的说明将android-support-v7-appcompat导入工作区
我可以将appcompat项目添加为当前项目(eclipse)中的库.
现在,当我使用以下import语句时没有错误.
import android.support.v7.app.ActionBarActivity;
Run Code Online (Sandbox Code Playgroud)
从ActionBarActivity扩展我的类时没有错误.
public class MyClass extends ActionBarActivity implements ActionBarListener {....}
Run Code Online (Sandbox Code Playgroud)
但是,我在使用AppCompat样式时遇到错误.
在清单中,
<activity
android:name=".Activity1"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
>
....
</activity>
Run Code Online (Sandbox Code Playgroud)
在styles.xml中,
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
</style>
Run Code Online (Sandbox Code Playgroud)
在使用parent ="Theme.AppCompat.Light"时,我在styles.xml中收到以下错误:**错误:检索项目的父项时出错:找不到与给定名称"Theme.AppCompat.Light"匹配的资源.**
为什么我无法从appcompat支持库访问资源.
Ps:我没用过 android:showAsAction="never"
我的应用程序项目和appcompat都在同一个文件夹中(我将它们都复制到当前工作区).
eclipse android android-theme android-support-library android-actionbaractivity
我创建了自定义主题,在我的布局中,我有几个EditText视图.自从我开始
android:selectAllOnFocus="true"
Run Code Online (Sandbox Code Playgroud)
,我注意到选择的颜色是我手机的默认颜色,所以我想知道我可以设置一些属性,当然,在我的主题定义中有一个想要的效果,即设置选择的颜色需要的颜色?
最好的,Deveti
我是android开发的新手,所以请耐心等待.我的应用程序元素(按钮颜色,背景颜色,文本颜色,分隔符颜色等)使用colors.xml中的颜色,例如使用"@ color/mycolor".
我的colors.xml看起来像:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="mycolor">#202020</color>
<color name="white">#FFFFFF</color>
<color name="whitehint">#50FFFFFF</color>
<color name="primary">#673AB7</color>
<color name="primary_dark">#512DA8</color>
<color name="primary_light">#D1C4E9</color>
<color name="accent">#794cc9</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#a4a4a4</color>
<color name="icons">#FFFFFF</color>
<color name="divider">#B6B6B6</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
现在我有一个菜单,用户可以选择一个不同的主题,我想使用第二个colors2.xml,例如,它具有相同的颜色名称,但键的十六进制代码不同.如何查看我的应用程序引用的xml文件?
我有包含三个片段的 minidemo。一个显示两个TextView和一个editview直接,下一个使用自定义适配器将相同的布局视为列表中的行,第三个显示一个带有标准适配器的普通列表(simple_list_item_1)
活动使用标准主题(Theme.AppCompat.Light.DarkActionBar),我没有修改。
我本来希望所有三个块的样式都相似。相反,带有自定义适配器的第二个块似乎根本没有根据浅色主题进行样式设置。(见文末截图)
理想情况下,我希望自定义列表的行的样式类似于第一个块。或者,我想应用第三个块的样式。但是,所有字体和背景似乎都有些偏色,我不确定如何找出当前用作主题一部分的内容。因此,通过手动分配文本颜色、大小、背景等来修复中间块的样式不是一种选择。
整个演示请参考MiniDemo
这是 item_row.xml 布局文件(顶层相对布局标签好像被编辑器剥离了。完整布局请到gitlab)
<TextView android:text="large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceLarge"
android:id="@+id/text1_field" />
<TextView android:text="large inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2_field"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="5"
android:id="@+id/edit_field"
android:layout_alignParentRight="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
自定义片段。同样,完整版在gitlab 上
public class CustomItemFragment extends ListFragment {
String[] DATA = new String[] {"foo1", "foo2", "foo3"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ItemAdapter adapter = new ItemAdapter(this.getActivity().getApplicationContext(), DATA);
setListAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)
}`
适配器(gitlab):
public class …Run Code Online (Sandbox Code Playgroud) android listview android-appcompat android-arrayadapter android-theme
我正在使用Android Studio主题编辑器为我的Android应用程序设计一个新主题.
我无法更改选项菜单文本颜色的文本颜色.
我已经尝试编辑xmls,没有任何工作来改变选项项目菜单.
我在所有styles.xml中使用了以下行而没有任何更改...其中没有带文字的行对菜单项文本颜色没有任何影响.
<style name="AppBaseTheme" parent="android:Theme.Material.Light">
<item name="android:colorBackground">@color/background</item>
<item name="android:colorAccent">@color/accent</item>
<item name="android:colorPrimary">@color/accent</item>
<item name="android:colorForeground">@color/common_signin_btn_dark_text_pressed</item>
<item name="android:textColorPrimary">@color/text_color_primary</item>
<item name="android:textColorSecondary">@color/text_color_secondary</item>
<item name="android:textColorTertiary">@color/text_color_secondary</item>
<item name="android:textColorSecondaryInverse">@color/text_color_inverse</item>
<item name="android:colorPrimaryDark">@color/background</item>
<item name="android:textColor">@color/text_color_primary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
整个应用程序代码库可以在这里查看...
我有一个日期选择器对话框,其主题是
<style name="DatePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/that_blue_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我创建此自定义主题是因为我想更改datePickerDialog的背景颜色。我设法改变了背景的颜色,选择器圆圈和按钮的文字颜色。但是我现在想更改CANCEL按钮的文本颜色,并OK保持按钮的文本颜色不变。我该怎么做?
我一直在尝试在我的项目中实现动态它们,但由于某种原因它给出了以下错误。这就是我试图实现它的方式。
首先,我定义了一些自定义属性,例如:
<resources>
<attr name="themeWindowBackground" format="reference" />
<attr name="themeContentBackground" format="reference" />
<attr name="themeContentTextColor" format="reference" />
<attr name="themeContentTextColorOnPrimary" format="reference" />
<attr name="themeTextColorSuccess" format="reference" />
<attr name="themeTextColorFailure" format="reference" />
Run Code Online (Sandbox Code Playgroud)
然后我在 style.xml 文件中定义了自定义主题
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@drawable/bg_splash_screen</item>
</style>
<style name="AppTheme.Black" parent="AppTheme">
<item name="colorPrimary">@color/material_dark</item>
<item name="colorPrimaryDark">@color/material_primary_dark</item>
<item name="colorAccent">@color/material_accent</item>
<item name="themeWindowBackground">@color/dark_gray</item>
<item name="themeContentBackground">@color/dark_slate_gray</item>
<item name="themeContentTextColor">@color/white</item>
<item name="themeContentTextColorOnPrimary">@color/teal</item>
<item name="themeTextColorSuccess">@color/green</item>
<item name="themeTextColorFailure">@color/red</item>
</style> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Material Components 库在我的应用程序中实现 Material Design。我希望我的图标和后退箭头为白色,但我无法更改它们的颜色。我的代码哪里出错了?
我尝试在我的样式 'NITraffic.Toolbar' 中添加以下属性,但没有效果:
<item name="subtitleTextColor">@color/color_on_primary</item>
<item name="android:colorControlNormal">@color/color_on_primary</item>
<item name="android:textColorSecondary">@color/color_on_primary</item>
Run Code Online (Sandbox Code Playgroud)
我在 theme.xml 中的顶级主题:
<style name="NITrafficTheme.DayNight" parent="Base.NITrafficTheme"/>
<style name="Base.NITrafficTheme" parent="Base.MaterialThemeBuilder">
<!--Material color attributes -->
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryVariant">@color/color_primary_variant</item>
<item name="colorSecondary">@color/color_secondary</item>
<item name="colorSecondaryVariant">@color/color_secondary_variant</item>
<item name="android:colorBackground">@color/color_background</item>
<item name="colorSurface">@color/color_surface</item>
<item name="colorError">@color/color_error</item>
<item name="colorOnPrimary">@color/color_on_primary</item>
<item name="colorOnSecondary">@color/color_on_secondary</item>
<item name="colorOnBackground">@color/color_on_background</item>
<item name="colorOnSurface">@color/color_on_surface</item>
<item name="colorOnError">@color/color_on_error</item>
....
<!--Component styles-->
<item name="materialAlertDialogTheme">@style/ThemeOverlay.MaterialComponents.Dialog.Alert</item>
<item name="bottomSheetDialogTheme">@style/NITraffic.BottomSheetDialog</item>
<item name="toolbarStyle">@style/NITraffic.Toolbar</item>
<item name="bottomNavigationStyle">@style/NITraffic.BottomNavigation</item>
</style>
<style name="Base.MaterialThemeBuilder" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor">?colorPrimary</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">false</item>
<item name="android:navigationBarColor">?colorPrimary</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
<item name="android:navigationBarDividerColor" tools:ignore="NewApi">?colorPrimary</item> …Run Code Online (Sandbox Code Playgroud) xml android android-theme android-styles material-components-android
为什么我的警报对话框不适应我手机的暗模式?在我的手机中激活暗模式时,几乎看不到两个按钮的文本,而标题和消息颜色则相反。为什么按钮颜色也不反转?该图标在非深色模式下也不能很好地显示。如何解决所有这些问题?
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.title))
builder.setMessage(getString(R.string.message))
builder.setPositiveButton(getString(R.string.positive)) { dialog, which ->
Toast.makeText(applicationContext, getString(R.string.pos_toast), Toast.LENGTH_LONG).show()
}
builder.setNegativeButton(getString(R.string.negative)) { dialog, which ->
Toast.makeText(applicationContext, getString(R.string.negative_toast), Toast.LENGTH_LONG).show()
}
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.show()
Run Code Online (Sandbox Code Playgroud)
我的 stiles.xml:
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="generalnotitle" parent="MyTheme">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud) android android-theme android-alertdialog kotlin material-components-android
android ×10
android-theme ×10
java ×2
material-components-android ×2
xml ×2
colors ×1
eclipse ×1
kotlin ×1
listview ×1