How to remove extra blank space from Menu - android

I am new in Android and using Overflow Menu in my program,
I need to know few things:
Question 1: How to remove extra blank space in Options, like in : Video, Email
Question 2: Want to hide both Activity Name or Application Name and ICON from FirstActivity
View my code below,
Menu > items.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/gamepad"
android:title="#string/gamepad"
android:icon="#drawable/gamepad"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/camera"
android:title="#string/camera"
android:icon="#drawable/camera"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/video"
android:title="#string/video"
android:icon="#drawable/video"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/email"
android:title="#string/email"
android:icon="#drawable/email"
android:showAsAction="ifRoom|withText"
/>
</menu>
Manifest.xml:
<application
android:icon="#drawable/ic_launcher"
android:uiOptions="splitActionBarWhenNarrow"
android:allowBackup="true" >
<activity
android:name="com.sample.menu.HomeActivity"
android:label="Demo App"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sample.menu.FirstActivity"
android:label="First Activity">
<intent-filter>
<action android:name="com.sample.menu.second" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
FirstActivity.java:
public class FirstActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_first);
getOverflowMenu();
}

For question 2 add
requestWindowFeature(Window.FEATURE_NO_TITLE);
Right before :
setContentView(R.layout.activity_first);

To Full Screen use,
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_layout);
FOR OVERFLOW MENU, please elaborate more What u want..?

for your Question 2:
in onCreate()
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this is to make action bar icon transparent
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
in Manifest.xml
<android:theme="#android:style/Theme.NoTitleBar">
For your Question 1:
this link is useful for you

Related

How to change the base color of an application

When I launch my application, the screen goes white before displaying my Splash Screen
I would like to remove if possible or put the background the same color as my Splash Screen
But I do not know how, Can someone help me
Thank you
You need to remove your splash screen code as the white screen is itself a splash, provided by android. You just need to change it according to your need.
You first need to create a drawable with name splash_screen.xml and put this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/black"/>
<item
android:drawable="#mipmap/ic_launcher_round"
android:gravity="center"/>
</layer-list>
after that you need to create a activity which launches your MainActivity
Something like this
class OnBoardingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DashboardActivity.launch(this)
finish()
}
}
then you need to overwrite the default splash screen with your styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
after that last step is to add this theme in your manifest.
the activity which launches the app will have this style
<activity
android:name=".ui.onboarding.OnBoardingActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you could use separate activity for your splash screen
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddddd"
tools:context=".SplashScreen">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_icon" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Splash Screen"
android:textSize="25sp" />
Class
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(getApplicationContext(),MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
}, 2000);
}
}
Manifest
( Launch Activity as SplashActivity )
<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/Theme.SplashtoMain">
<activity android:name=".MainActivity"/>
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

SplashScreen approach defined in xml (without activity) does not appear

I have defined splash screen like many other without external activity, but it doesn't works for me, I don't understand why.
Is there any limitations for images? Also tried for many other images
This is my splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash_logo" />
</item>
</layer-list>
Here preview for splash.xml file in android studio looks like perfectly.
Than I have created style like that
<style name="AppTheme.Launcher">
<item name="android:windowBackground">#drawable/splash</item>
</style>
and assigned it to activity theme inside manifest
<activity
android:theme="#style/AppTheme.Launcher"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
this is my activity's
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
when activity is loaded blank white screen is shown instead of image, maybe for a one second. I searched this approach and seems that it is the same what others were done. Don't understand what's wrong
EDIT:
I have tested it for another device OS 5.0 and it works, but for 6.0 doesn't
EDIT
Remove this from your activity
setTheme(R.style.AppTheme)
Try this
Style.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background</item>
</style>
splash_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/colorPrimary" />
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher" />
</item>
</layer-list>
SplashActivity
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
startActivity(new Intent(SplashActivity.this, MainActivity.class));
// close splash activity
finish();
}
}
Manifest
<activity android:name=".SplashActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This should be a comment. But i cannot put a comment. I have faced the same problem. Please check your size of image. Try to compress the image and try again it may help you. Please do let me know.

Animation in Splash Screen

I use this splash screen for my app. It works fine, but I want to use animation. How can I use animation without layouts?
This my java file:
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, NavigationActivity.class);
startActivity(intent);
finish();
}
}
My xml for theme:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorMaterialWhite"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ico" />
</item>
</layer-list>
Style:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
AndroidManifest:
<activity android:name=".SplashActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I want rotate ico while app loading. Thank you.
Is it even possible?

How to add a split ActionBar in android.I have got everything right but it still doesn't work.

here is my code
MainActivity
public class MainActivity extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
menu_main.xml
<menu 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" tools:context=".MainActivity">
<item android:id="#+id/action_settings" android:title="#string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
<item android:id="#+id/one" android:title="oneone"
android:orderInCategory="100" app:showAsAction="always" />
<item android:id="#+id/two" android:title="twotwo"
android:orderInCategory="100" app:showAsAction="ifRoom" />
<item android:id="#+id/three" android:title="threethree"
android:orderInCategory="100" app:showAsAction="ifRoom" />
<item android:id="#+id/four" android:title="fourfour"
android:orderInCategory="100" app:showAsAction="ifRoom" />
</menu>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sanjith.actionbartwo" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<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>
This code gives me three buttons on the actionbar and one on the overflow.
I want to get all the buttons on the bottom actionbar.I have searched the internet for this but i haven't found a solution.
Please help.
Try this http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar
<manifest ...>
<activity uiOptions="splitActionBarWhenNarrow" ... >
<meta-data android:name="android.support.UI_OPTIONS"
android:value="splitActionBarWhenNarrow" />
</activity>
</manifest>
I have encountered this problem before unfortunately the action bar doesn't split by code you need to fill all the room available so the action bar would split by itself with your permission of course but there are no possible way to split it if it still have space

Cannot combine custom titles with other titles features error

I have a tabhost and there is an activity inside. I want this activity to have customized title bar so I used the following code. But it gives the error Cannot combine custom titles with other titles features. I look at the file and see only one theme applied to it, I am not sure why this is happening... Any idea? I am also using dialogtheme for other activities in my tabhost, but I think that is fine because I am applying my custom theme only to one Activity(which is named startActivity).
Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainTabActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
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=".StartActivity"
android:label="#string/app_name"
android:theme="#style/CustomTheme" //this is the Custom title bar theme for this activity
android:screenOrientation="portrait" >
</activity>
Activity onCreate():
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //error happned here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate()");
setContentView(R.layout.startactivity);
window_title.xml in layout folder:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="#+id/header"
android:src="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Finally, the #style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>

Categories

Resources