App Bar is not showing in Android Studio but showing on an actual android device - android-studio

I have already checked similar problems like mine but none of it helped. I also checked my previous project with the same AppTheme, they are the same but I have noticed everytime I create a new android project, the App bar is not showing even after several "Rebuild Project".
This is what my styles.xml shows
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
This is what my AndroidManifest.xml shows
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mycontact">
<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>
</manifest>
My MainActivity.java (Haven't put code yet)
package com.example.mycontact;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
And my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
</LinearLayout>
I have also tried changing the layout from ContraintLayout, RelativeLayout but nothing has changed. Zooming in and zooming out the layout doesn't change at all. Here is a snapchat.. Thank you for your help.
activity_main.xml page

Your styles.xml and other files seem to be in order, so try the following out.
Click the "Eye" icon on the toolbar above the XML Layout Preview, and then select "Show Layout Decorations" if it is unchecked. This should make it display both the AppBar and the system navigation bar.
Screenshots for reference, taken on Android Studio 3.3:
1. Layout with decorations missing
2. Press the 'Eye' icon, and select the option
3. The decorations (AppBar and system navigation bar) should now be visible

Related

Hide navigation bar COMPLETELY (Android Studio)

There are many videos about hiding navigation bar by using setSystemUiVisibility or something like this. However, navigation bar is being showed again after using keyboard to write username or password. And probably that solution will be broken because of other things. Help me to hide navigation bar completely like in the games. My app just don't need that.
In your res/values/styles.xml file copy this style:
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
Here the parent theme is the theme you are currently using. Typically it will be in the file like this as default:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Then go to the AndroidManifest.xml and make it like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package.name">
<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
android:theme="Apptheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
What you do here is change your activity's theme to Apptheme.NoActioBar theme.
Then run your app and you will have no action bar.

Android Studio Not Applying My Design Changes

I'm trying to change the theme of some activities by removing the action bar or changing the title of it. At first i was doing it using the AppTheme option in the design tab. However, after searching online i knew that i was doing it the wrong way, so i proceeded to the AndroidManifest file to do my changes manually. Unfortunately, it's not working either. Here's the code of my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.wonderheart">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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"
android:label="Sign Up"/>
<activity
android:name=".Login"
android:label="Log In"/>
<activity android:name=".drawable.welcome">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".UserProfile"
android:theme="#style/AppTheme.NoActionBar"/>
<activity android:name=".HomePage" >
</activity>
</application>
</manifest>
Here are some of my activities that I'm trying to change:
Action Bar Title Changed Successfully
Action Bar Title Didn't Change
I'm using Android Studio 3.0 Preview and Kotlin. I hope you can help because i can't progress on my work without fixing this design issue!
You can fix problem two way.
1. Use common one theme for all activities and use code for hiding and showing action bar in onCreate method
// Set up the toolbar
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
var actionBar = supportActionBar
//For hiding android actionbar
actionBar.hide();
//For showing android actionbar
//actionBar.show();
Use custom style for activity where you don’t want to show action bar in example below I did it for application level but you can use it your way with your any other activities
style.xml
<resources>
<style name = "AppTheme" parent = "android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name = "NoActionBar" parent = "#android:style/Theme.Holo.Light">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
</style>
</resources>
AndroidManifest.xml
<application
android:allowBackup = "true"
android:icon = "#drawable/ic_launcher"
android:label = "#string/app_name"
android:theme = "#style/NoActionBar" <!--This is the important line-->
>
<activity

How to hide toolbar with drawer layout and still be be able to use the open drawer button(three lines)?

I'm new to android and I'm trying to hide toolbar in drawer
layout for a time now but couldn't do it.If I change primary
color to 0 opacity then I get "A TaskDescription's primary
color should be opaque" error I know the reason of the error
so I've to set 255 opacity to primary color as taskDescription
takes primary color. I want the following UI;
[UI1
I've used following theme;
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
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="NoActionBar" 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>
manifest ;
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/NoActionBar"
android:supportsRtl="true">
<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>
I did manage to transparent the status bar by setting up primaryDark color to opacity 0.
color.xml ;
<?xml version="1.0" encoding="utf-8"?><resources>
<color name="colorPrimary">#3f51b5</color>
<color name="colorPrimaryDark">#00303f9f</color>
<color name="colorAccent">#FF4081</color>
<color name="toolbarcolor">#00ffffff</color>
Use tooolbar.hide() method or instead you can use scrollbars to whole activity with toolbars so that it will give a hide toolbar behaviour
or just give a trasparent color to toolbar
I hope it will help a little bit

Android custom theme won't apply

For my application I want to make a custom theme with just a different color for my actionbar. So I found a theme generator on the Internet:'Android Action Bar Style Generator'. I picked some color and downloaded the theme, put my downloaded stuff in the res-folder and changed the 'style' to my new theme. For some reason my theme never applies to my application. It always uses the baseTheme which is also specified in the downloaded theme. This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jobslot.indupac" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/bpi_logo_transparant_background"
android:label="Indupac"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity">
</activity>
<activity
android:name=".GraphActivity">
</activity>
</application>
</manifest>
This is my style:
<resources>
<color name="basic_text">#000000</color>
<color name="basic_text_buttons">#FFFFFF</color>
<color name="blue_bpi">#003676</color>
<color name="light_green_bpi">#D6FFDA</color>
<style
name="AppTheme" parent="#style/Theme.Indupac">
</style>
</resources>
I found a solution for my problem. When I applied the default theme "#style.AppCompat.Light.DarkActionBar" and added "colorPrimary" as an item, then it worked like a charm. Keep in mind not to put "android:" in front of "colorPrimary", because that requires API 21. Here is what i got:
<resources>
<color name="basic_text">#000000</color>
<color name="basic_text_buttons">#FFFFFF</color>
<color name="blue_bpi">#003676</color>
<color name="light_green_bpi">#D6FFDA</color>
<style
name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue_bpi</item>
<item name="colorAccent">#color/blue_bpi</item>
</style>
</resources>

How to design a spinner in Android

I want to design a spinner as displayed in the image below:
I am not getting the arrow symbol pointing downside in spinner. How can I do this?
If I make a button design like shown above then I have to write extra code to get similar functionality as for a spinner, as Spinner doesn't have android:drawableRight="#drawable/arraodown", but in the button we have this method.
Do not mess around with right/left/... drawables.
Just set one 9-patch drawable as background that limits the inner content.
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/you_spinner_drawable" />
Regarding the 9-patch drawable have a look at the android resources or at this example picture taken from this blog post (which shows in little more detail on how to make a custom spinner):
For information about 9-patch drawables see the android documentation:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
http://developer.android.com/tools/help/draw9patch.html
Of course you can also specify a State list xml file as drawable, eg.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When disabled -->
<item android:state_enabled="false"
android:drawable="#drawable/your_disabled_spinner_drawable" />
<!-- When selected -->
<item android:state_pressed="true"
android:drawable="#drawable/your_selected_spinner_drawable" />
<!-- When not selected-->
<item
android:drawable="#drawable/your_default_spinner_drawable" />
</selector>
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/you_spinner_drawable" />
**You can use the below mentioned Drawable to set as background for this spinner**.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When disabled -->
<item android:state_enabled="false"
android:drawable="#drawable/your_disabled_spinner_drawable" />
<!-- When selected -->
<item android:state_pressed="true"
android:drawable="#drawable/your_selected_spinner_drawable" />
<!-- When not selected-->
<item
android:drawable="#drawable/your_default_spinner_drawable" />
</selector>
You will have to create a custom layout for the spinner. I think the following XML might give you an idea.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="3dip">
<TextView
android:id="#+id/number"
android:padding="3dip"
android:layout_marginTop="2dip"
android:layout_marginLeft="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Just use GIMP as your image editor and change background color and border with a color you like.
For example, I did this image by editing an existing one I found on the Internet: http://sdrv.ms/1lRkTbG

Resources