In my android app, I am getting the warning about the possible overdraw. I am trying to follow the thread here to fix it:
"Possible overdraw: Root element paints background "
But If I try it, it makes all my layouts messed up, like the buttons are in different places and different looking, and if I open a dialog box, its width is really small...
I made a theme here:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:background">#drawable/bg_normal</item>
</style>
</resources>
Then in manifest I have
<activity
android:name="com.activity.idsconnect.ActivityAdminMainMenu"
android:label="#string/title_activity_activity_admin_main_menu"
android:theme="#style/MyTheme"
android:screenOrientation="portrait" >
</activity>
And then removed the background attribute from the root linear layout on the activity.
Am I doing something wrong here? Does anyone know?
Thanks.
Related
I'm doing some UI designing for class on an open source project. I'm trying to make the appbar and tabs of this tablayout transparent but no matter what I do they remain white. If it were transparent the background would be able to be seen but i get this white instead.
I have tried-
changing the xml values in the mainfragments xml to transparent
changing the colors.xml values to transparent (all of them because i wanted
to be sure)
changing and even removing the "light theme" and "dark theme" values in
styles.xml and removing the app theme line in the android manifest
android:theme="#style/AppTheme.FullScreen.Light"
Am I missing something else that i can try? I would be very thankful for any suggestions.
in style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
in color.xml
value #color/transparent is the color value #00000000
<activity android:name=".YourActivity" android:theme="#style/Theme.Transparent">
</activity>
set alpha value in layout XML or dynamically in view to make view transparent.
view.setAlpha(40);
oR add from xml - value between 0 to 1
android:alpha="0.4"
In android Studio res->values->colors.xml
Step 1 : For selecting color
Step 2 : Changing transparency(you can move left to right for adjusting transparency )
Step 3 : Give this color as views background
<RelativeLayout
android:id="#+id/top_bar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/color_name">
This may help you.
I am trying to add a splash screen to my app to display while everything is loading. I followed this post to do this via a theme. It looks to be working the way I want, but shortly after the splash is displayed the app crashes when trying to customize the ActionBar.
theme.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.SplashScreen" parent="#style/Theme.AppCompat">
<item name="android:windowBackground">#drawable/orange_background</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Relevant section of AndroidManifest.xml
<application
android:allowBackup="true"
android:theme="#style/CustomActionBarTheme"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:largeHeap="true" >
<activity
android:name="com.example.app.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.SplashScreen"
android:screenOrientation="portrait" >
Section in MainActivity.java causing crash
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Caused by: java.lang.NullPointerException at android.support.v7.app.ActionBarImplICS.setDisplayHomeAsUpEnabled(ActionBarImplICS.java:174) at android.support.v7.app.ActionBarImplJB.setDisplayHomeAsUpEnabled(ActionBarImplJB.java:20)
NOTE: This crash only started happening after I implemented the splash screen.
I guess it's a conflict with windowNoTitle and setDisplayHomeAsUpEnable.
For the splash screen, you disable the Title(and the full ActionBar), and in MainActivity.java you try to set an up button in the disabled ActionBar.
You might want to use the code from this post.
why do you need to get action bar in splash screen?
once you define:
<item name="android:windowNoTitle">true</item>
getActionBar always returns null
Adding "android:windowNoTitle" means no action bar is created. Therefore getSupportActionBar() will return null.
I would like to set the default menu inflator background color to white for any and all menu items created in OnCreateMenuOptions activity please?
You will need to create a Theme based on another one (Or create one from scratch). Something like this will define your theme in the resources:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base" parent="#android:style/Theme.Light.NoTitleBar">
<item name="android:background">#android:color/white</item>
</style>
</resources>
Then you need to apply it to the application in your manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/Base">
I developed a android homescreen, the code seems right but when I run the project I get the following error:
java.lang.RuntimeException:
Unable to instantiate activity ComponentInfo{com.matthieu.launcher/
com.matthieu.launcher.DragableSpace}:
java.lang.InstantiationException: com.matthieu.launcher.DragableSpace
Here is the complete log: http://pastebin.com/iYtYW2W6
The code is straight from the Android Launcher.
DragableSpace: http://pastebin.com/jpWDtFPF
MainActivity:
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DragableSpace space = new DragableSpace(this.getApplicationContext());
setContentView(space);
}
}
attr.xml in values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="DragableSpace">
<attr name="default_screen" format="integer"/>
</declare-styleable>
</resources>
Three xml files initial_screen, left_screen and right_screen, all have same code apart from the id:
<LinearLayout android:id="#+id/center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.matthieu.launcher"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Any ideas how to fix that?
Had a quick look at the code as it is now. NullPointerException at line 169 of DragableSpace, due to no child view - fix this by adding a child view in the MainActivity:
TextView child = new TextView(this);
child.setText("This is a Test");
space.addView(child);
So now the code runs and logs the touch events to LogCat but nothing appears to happen (I'm guessing you want 3 spaces which can be dragged and repositioned on the screen) - some initial problems, I think, the SNAP_VELOCITY value of 1000 seems a bit high to me for some dragging gestures, none of the layout xml files appear to be used, and if the current 'screen' is the full width and height of the device, where does it get dragged to?
Updated: Add the previous post's xml layout as the main.xml:
<?xml version="1.0" encoding="utf-8"?>
Now, in the MainActivity, set the content as:
setContentView(R.layout.main);
Also, to make it easier to see what's happening, I set the background colours to different colours - add the following colours to the strings.xml file:
<color name="green">#21d081</color>
<color name="blue">#00A0FF</color>
<color name="orange">#EA6700</color>
And edit the screen xml files to add a colour e.g. in the left_screen.xml file, add the following attribute:
android:background="#color/blue"
And use a different colour for the initial_screen.xml and the right_screen.xml and when you run the project, you can drag across the screen and reveal a new area.
On a side note, and this is more of an observation, in your DragableSpace code i've noticed two things.
In public DragableSpace(Context context, AttributeSet attrs) {... you haven't called a.recycle(); after you've accessed all your properties of obtainStyledAttributes. This is bad i think.
I'm not entirely sure, as i've just picked up java, but i found that i had to change super.DragableSpace(...) to this.DragableSpace(...). This could have just been particular to my component, but wasn't entirely sure if that was correct or not.
DragableSpace is a ViewGroup. DragableSpace is not an Activity. Home screens are activities. Hence, DragableSpace cannot be a home screen.
How to add a background theme and/or background wallpaper to my app? Right now my app background is plane.
Create an XML file in the values directory that contains the style. It could be something like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourTheme" parent="#android:style/Theme">
<item name="android:windowBackground">#drawable/your_background</item>
</style>
</resources>
For the case above to work, you need to have an image called your_background.png in the drawable folder. Then, you can apply that style to either your whole app or one specific activity by doing this in your manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bla.bla">
<application android:theme="#style/YourTheme"> <!-- This is for the whole app -->
<activity android:name="bla.bla.YourActivity"
android:theme="#style/SplashTheme"/><!-- This is for a specific activity -->
</application>
</manifest>
You might be using some layout XML for UI. Set layout (linear, relative, etc) background with any image you want to set your background to. Make sure that the image is available in the res/drawable folder.