The default android spinner just shown a little arrow down. So, I tried to use Widget.Holo.Spinner which show an underline. Here is my style:
<style name="XRSpinner" parent="android:Widget.Holo.Spinner">
...
...
...
</style>
It shows ok on preview, but when I run it, the spinner shown a black background. I have also tried with parent="android:Widget.Holo.Light.Spinner", but it still shows a black background.
Any ideas?
Thanks!
UPDATED
Here is my application manifest
<application
android:name=".XRWareStock"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar" >
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My minSdkVersion is 19 and targetSdkVersion is 25.
The default android spinner just shown a little arrow down
Holo themes are deprecated; don't worry, you don't have to reinvent the wheel to create a custom spinner layout, there are several solutions like BetterSpiner which makes your life easier. It comes with several styles.
Do you wish to have an underline and/or change the arrow?
For the underline, you can change your style's parent to:
style="#style/Base.Widget.AppCompat.Spinner.Underlined"
So for your style's name:
<style name="XRSpinner" parent="Base.Widget.AppCompat.Spinner.Underlined">
If you want to change the arrow's color:
Java
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.YOUR_COLOR), PorterDuff.Mode.SRC_ATOP);
XML
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/YOUR_COLOR" />
Related
I am writing a very simple app as a starter and using a material design icon as the launcher icon. Is there a way I can set the colour of just the launcher icon like I can the size and shape?
Here is my code from AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/gasstation"
android:label="#string/app_name"
android:iconTint="#color/sysGreen"
android:roundIcon="#drawable/gasstation"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The statement android:iconTint seems to be OK in that Android Studio has not flagged it as an error but it has no effect. The launcher icon is still the grey colour of the downloaded image resource.
Is this possible? Any help greatly appreciated.
If you retrieve the icon from a drawable, basically a small image you have in your resources, you cannot change the color.
What you can instead do is to use the tool Image Asset Studio, here is the link
As explained
In the Project window, select the Android view. Right-click the res
folder and select New > Image Asset.
then follow the guide..
Anyway from API version 21, you can tint drawables,
as explained in this post
Well ... I finally did it as follows.
right click on res>new image asset>clip art>pick the icon
you can set the foreground colour manually in the Configure Image Asset screen
When I am designing a layout, the design review does not show the title bar, but the simulator can show the title bar, as you can see below:
My style.xml is showing as follows:
Also, my Manifest is writen as follows:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Is there any ways that I can keep the title bar all the time when I design my layout? even though I create many layout file, I still hope that every layout can keep the title bar.
You need to change theme in Editor
like below image it will work
Check the current Theme in the Android Studio Design Preview :
It must not end with ".NoActionBar", you can set your theme "AppTheme".
If you are using 28 API. please change API VERSION to 26 and use this
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
I wanted to add a SplashScreen to my app and did a little research on the matter. Some tutorials said that you could create an activity and with some timers show it for a few seconds. I couldn't get them working, and then in this page How do I make a splash screen? the second top voted answer said that instead of showing an activity (and because of that wouldn't substitute the white/black launch loading screen but instead add more delays) you should instead create a custom style and assign it to your activity in the Manifest file. I did that, created a new Style like this:
<style name="splashScreenTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/launchscreen</item>
</style>
in the styles.xml and changed my Manifest to this:
<application
android:name=".EFBApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivityDrawer"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/splashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I run my app I can see the launch screen perfectly but then it crashes. By breakpoints I discovered that when the MainActivityDrawer (my main class) gets to the super.onCreate(savedInstanceState); line it then crashes (it goes to the ZygoteInit.java class and after that it crashes while breakpoint debugging). If I take away the android:theme lines in the Manifest it works fine but shows the horrible plain white screen while launching. Any suggestions or ideas? Thanks a lot.
Ok, so I managed to make it not crash, instead of assigning the parent as Theme.AppCompat.NoActionBar, I used just AppTheme and it works now. I hope this helps anyone.
I want to override a application theme on a particular activity, but its not working for me
This is code on my Manifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:theme="#style/MyTheme"
android:name="com.ssdevnet.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ssdevnet.Home"
android:label="#string/app_name" />
</application>
And this is what i used in style:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
</style>
and its still not working on Android 2.3.6 or below but working on 3 and above.
Also i tried to use this on the oncreate method on class file for that particular page:
requestWindowFeature(Window.FEATURE_NO_TITLE);// Removes title bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
but its not working on my phone running Android 2.3.6 but its working on Emulator running Jellybean and i need something that works on all the versions.
And I need to know some things as i am a newbie to android:
Can we define a Global theme, and override that theme on some activities? if yes, what method can we use?
Or we have to define theme for every activity if we are targeting activities instead of app?
I also want to learn about deploying the custom themes in the app.. if there are some good tutorials and references please share.
Thanks in Advance!
Try using setTheme(..) before calling setContentView(...) and super.oncreate() and it should work fine in the Activity.
Check out the Android developer's site for more information.
I am simply trying to change the background color for an activity, however nothing has changed.
Here is the relevant XML:
styles.xml
<resources>
<style name="STBTheme" parent="android:Theme.Light" >
<item name="android:windowBackground">#color/blue</item>
</style>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pedro.stb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/STBTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/STBTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Furthermore, I'm using Eclipse, and by changing the theme in the activity's xml, it does not change in the graphical layout.
Any help?
Edit
Got it to work. Have to clean the project before reloading the layout. Very annoying...
i had check your code its ok .
try <item name="android:Background">#ccff33</item>
instead of your <item name="android:windowBackground">#color/blue</item>.
and you have write android:theme="#style/STBTheme" > in application as well as activity also.
Just write in application tag .
Hope you will get your output now.
Open the preview of your activity and Click on the circled button as shown
Type the name of your custom theme and Click 'OK' as shown
In Manifest file add the attribute android:theme=".YourTheme" to the required Activity
You will have the theme of the current activity changed.
I dont know why Android Studio acts like it's drunk sometimes. I have two projects with same target,minimum SDK active. One of them had the splash screen theme implemented correctly, the other just wont show until I found this workaround.