How do I change the theme of a SettingsActivity in Android? - android

TL;DR: How am I supposed to change the background of a SettingsActivity to be white or off-white to match Holo.Light? Changing the theme of the app changes the text but keeps the background as black.
I recently changed the theme of my application from default (Holo) to Holo.Light. Everything seemed to work perfectly until I opened my SettingsActivity and was greeted by this:
As you can see, all of the test is black on a black background.
This is the original:
I am trying to make the settingsActivity have a white background.
I have added the following to my Manifest:
<application
...
android:theme="#android:style/Theme.Holo.Light" >
...
<activity
android:name="edu.purdue.SafeWalk.settings.SettingsActivity"
...
android:theme="#android:style/Theme.Holo" >
</activity>
However even the redundant theme setting does not help.
Obviously it is changing the theme of the text, but not the background which leads me to believe that I have manually overridden the background color. However I have not defined a layout for this SettingsActivity and I see no XML or Java that sets the background.
I can post whatever other relevant code here, but the source is public here.
How am I supposed to change the background of a SettingsActivity to be white or off-white to match Holo.Light?

You'll want to remove
view.setBackgroundColor(getResources().getColor(android.R.color.black));
from line 101 of SettingsFragment.java, cheers!

Related

Force app widget's light theme on OnePlus phone with Android 12

I have a problem with forcing a light theme of home screen app widget on OnePlus 9 phone with Android 12 (using the OnePlus' launcher). My widget's theme inherits from Theme.MaterialComponents.Light and is light on Android 11 and below, even when the phone is in the dark mode.
Problem is on Android 12, where the widget's background is always very dark, when the phone is in the dark mode. When I set pure white background, it ends-up almost black. Pure red is dark red, pure green is dark green, etc. Looks like something in the system is tinting the background colors. The same is happening with Theme.Material3.Light and #android:style/Theme.DeviceDefault themes.
Everything is good on pure Android in an emulator, so this looks like a OnePlus issue. Any ideas what can be wrong and how to fix this?
Goto to your themes file and place the following line in the style you are using for your app.
<item name="android:forceDarkAllowed">false</item>
You can create a Application Class which extends Application() and place the following code in OnCreate() like this
class YourApplicationClass : Application(){
override fun onCreate() {
super.onCreate()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
Then in your manifest file add this application class like this
<application
android:name=".base.YourApplicationClass"
...
/>

Odd PreferenceActivity Theme on Samsung Devices

I'm seeing a very odd theme issue in my PreferenceActivity only on Samsung devices (as far as I'm aware).
-----EDIT (Removed irrelevant code)-----------
The following is an unthemed preference activity:
<activity android:name=".FullSettingsActivity"/>
Setting theme for the FullSettingsActivity:
<activity android:name=".FullSettingsActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
yields this:
So clearly the default theme for Samsung devices is rather odd. Is there any reason a PreferenceActivity would end up unreadable like that only on Samsung devices?
Try changing your theme from #style/Theme.AppCompat.NoActionBar to something else like android:Theme.Holo.Light.NoActionBar and see the difference.
Also make sure you add that GalleryTheme in your AppManifest.xml in your application tag like android:theme="#style/GalleryTheme"
Hope that helps.

change the background of actionbar from java code as defined in the style.xml

i have set the theme as:
<application
........
android:theme="#style/Theme.Example" >
.......
.......
</application>
i have several fragment in one activity. in one of my fragment i have change the color of actionbar as:
((MainActivity)getActivity()).getSupportActionBar()
.setBackgroundDrawable(new ColorDrawable(bitmap1.getPixel(0, 0)));
this works fine. now, i want to change the actionbar as it defined in #style/Theme.Example while i am traveling to another fragment.
after googling for several times, i find out only how to change the color or backround drawable of actionbar. not how to get back to the default actionbar style as it is defined in the style.xml
any help or link would be too much helpful :) thank you.
if it is needed, i can provide the style.xml. i have created them from this actionbar style generator tool
oh my god, i have found the answer in 5 min after posting the questions. i have used this:
Drawable d = getResources().getDrawable(R.drawable.ab_background_textured_example);
((MainActivity)getActivity()).getSupportActionBar().setBackgroundDrawable(d);
if you are asking that what the hell is R.drawable.ab_background_textured_example is, then you need to read my question properly and check out the link. on that page i have downloaded the zip file which contains the graphics. in the res/drawable there is a xml which is named ab_background_textured_example. and this is the default background of my actionbar. cheer.
if anyone need know more about it, just comment bellow.

Feature Custom Title: Cannot combine custom titles on API 11 and above

I have a project in which i setted:
minSdkversion setted to 10
MainActivity is a TabActivity
Code in onCreate method is this:
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
...
With previous settings, all works well! But, if i set minSdkVersion to 11 or above, this exception occurs:
android.util.AndroidRuntimeException: You cannot combine custom titles with other title features
I don't understand why happens this just changing minSdkVersion.
I red a lot about this problem on this site. I tried setting:
Theme.NoTitleBar in main layout and after in Manifest file too
I put those 3 lines in all possible positions
If i comment first line a NullPointerException occurs when i call something on my TextView reference of my CustomTitle layout
I tried setting, in theme.xml file declaration, "windowNoTitle" = true
Since i'm using functions available from API 11 only, i want to set minSdk to 11 before loading App on Store. How can i do ?? I need Help
Edit: With minSdkVersion = 10 and Theme.NoTitleBar in Manifest, same error occurs. Removing it, all works as before.
Can anyone provide a working code (manifest and activity code) for setting a custom title when API is 11 or above ? Thx much
Fixed by my self. I don't know why, but simply adding in manifest file "theme" property for each activity's declaration, all works:
From this:
<activity
android:name=".CheckActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
</activity>
To this:
<activity
android:name=".CheckActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="#android:style/Theme" >
</activity>
#kinghomer I have tried CUSTOM_TITLE its on 2.2 (API 8) actually. Let me try on API 11 and get back to you!
Before that, you need not make Theme.NoTitleBar anywhere, can be controlled in .java file directly. Give me some time, will be back!
res/values-v11 defalut use this code :
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
change "android:Theme.Holo.Light" to "#android:style/Theme" will be ok!
tips: if your project no have "res/values-v11", then check your project referenced "lib project" 。
Other than the accepted answer ,there is another way to solve this :
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme" >
assign a theme attribution to application in the xml-based mainifest,that should work for all activities.
This problem occurs when you try to add a custom title bar along with extending your activity by ActionBarActivity or AppcomActivity. These two activity classes already have title bar defined.
So, when you try to add your own custom title bar a conflict arises, which title bar to use - your custom one or the one provided by activity extended.
To solve this issue, just extend your activity by Activity which does not have any predefined title bars, so yours will be accepted without any conflict.
public void MyActivy extends Activity
{
// your code
}
I just added android:theme="#android:style/Theme" in activity in AndroidManifest.xml file and it worked super fine.
<activity
android:name=".MainActivity"
android:theme="#android:style/Theme" >
</activity>
Hope this works for you as well.
In your AndroidManifest file, use this snippet instead of yours.
From this:
android:theme="#style/AppTheme">
to this:
android:theme="#style/custom_title">

Android. Default text color

Hallo everybody,
I'd like to use black color as default text color only in one activity.
I guess, I should use Theme and Styles, but I didn't find any good information relating to my question or to only one activity.
Is it possible to change default text color only for one activity?
If yes, could you give me an example please, how to do this?
Mur
You can add the android:theme tag to just an activity:
<activity
android:name=".SomeActivity"
android:theme="#style/Theme.ForSomeActivity"
/>

Categories

Resources