styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
192.168Manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name=".app.App">
<activity
android:name=".activity.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
....
<activity android:name=".activity.TransferActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
TransferActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transfer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_base);
setSupportActionBar(toolbar);
Transfer activity.xml
<FrameLayout android:id="#+id/activity_transfer_fragment_container"
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"
tools:context="com.example">
<include
android:id="#+id/toolbar_transfer"
layout="#layout/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
/>
I tried a lot of combinations, but still cant get it working. Toolbar in Main activity is working without problems. But in other activities, eg. TransferActivity, I can see only design of toolbar, but it got no text in it.
getSupportActionBar().setTitle("Screen title");
Related
Noob here, having an issue with the action bar in landscape mode (want to keep it in portrait mode).
I post a sample of my manifest xml file having tried the info in other threads.
<?xml version="1.0" encoding="utf-8"?>
<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>
my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Primary theme color of the app (sets background color of app bar) -->
<item name="colorPrimary">#ffcfcf</item>
<!-- Background color of buttons in the app -->
<item name="colorButtonNormal">#ff8383</item>
</style>
<style name="AppThemeNoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
a snippet from my land\activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:style="#style/AppThemeNoActionBar">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/love3"
android:scaleType="centerCrop"/>
...
I have tried changing the parent in styles.xml from AppTheme to Theme.AppCompat.Light to no avail.
portrait layout xml does not have android:style="#style/AppThemeNoActionBar"
Any pointers would be great!
Try this in onCreate function below setContentView
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getSupportActionBar().hide();
}
you can do it like this,
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
I am using this theme in my Android app, Theme.AppCompat.Light.NoActionBar in every activity my project name i.e the label name from the Application tag appears in every Android activity, before it was not happening but recently it is happening. If I remove the label then the package name appears instead of the title.
What exactly is happening ?
I know that there are several ways to fix it but show me where I am wrong and what is happening ? Is it a bug ?
I referred a previous answer Android Application Name Appears as Activity Name and tried but still did not work, So here is a copy of my manifest.xml
<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>
<activity android:name=".Activity2"></activity>
</application>
Below is a sample screenshot, the label name can be seen although that activity(Activity2) consists of a toolbar , the white area is a edittext in the toolbar and nothing else is present inside the toolbar.
EDIT 1
<style name="AppTheme" 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>
<item name="android:textColor">#color/white</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
EDIT 2
public class Activity2 extends AppCompatActivity {
LinedEditText editText;
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
toolbar = (Toolbar) findViewById(R.id.toolbar);
editText = (LinedEditText) findViewById(R.id.editText);
setSupportActionBar(toolbar);
}
}
activity2.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"
android:orientation="vertical"
>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:id="#+id/toolbar"
>
<EditText
android:layout_width="250dp"
android:layout_height="40dp"
android:id="#+id/title"
android:background="#color/white"
android:layout_margin="10dp"
/>
</android.support.v7.widget.Toolbar>
<com.test.testproject.LinedEditText
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/editText"
android:gravity="top"
/>
</LinearLayout>
Check this out.
getSupportActionBar().setDisplayShowTitleEnabled(false);
Check with setting theme for specific activity..which solves your problem..try this
<style name = "NoActionBar" parent = "#android:style/Theme.Holo.Light">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
</style>
Just put in onCreate() method after setSupportActionBar(toolbar).
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setTitle("");
UPDATE:
This is your problem. Avoid using Toolbar.
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/green"
android:id="#+id/toolbar"
>
<EditText
android:layout_width="250dp"
android:layout_height="40dp"
android:id="#+id/title"
android:background="#color/white"
android:layout_margin="10dp"
/>
</android.support.v7.widget.Toolbar>
If you are using NoActionBar in your theme. Avoid using Toolbar in your Activity's layout. That is the reason you are getting the Activity name.
If you are using Toolbar make sure you disable the TITLE on it.
I created surfaceView like this.
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.networks.streaming.surfaceviewfullscreentest.MainActivity"
tools:showIn="#layout/activity_main">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/liveSurfaceView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:nestedScrollingEnabled="false"/>
</RelativeLayout>
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
SurfaceView liveSurfaceView = (SurfaceView) findViewById(R.id.liveSurfaceView);
liveSurfaceView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE
);
getSupportActionBar().hide();
}
this code works in android devices running Kitkat (API 19). but when I run the same code on devices running lollipop or higher the resultant display is like this.
the uper and lower borders are visible and surfaceView does not cover full screen. how can I fix this? Thanks
This is Example !!!
<application android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<activity android:name=".MainActivity" android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Add to style.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
I am getting two title bar has below ,i have designed a custom title bar with image and text and used styles.xml to set the theme.I have same titlebar for two screens with different text.
the code are has below
public class ReminderActivity extends Activity {
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.reminderlayout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
ArrayList<GetReminder> list = (ArrayList<GetReminder>) getIntent().getSerializableExtra("reminderList");
System.out.println("size is >>>"+list.size());
}
}
xml
<?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="35dip"
android:gravity="center_vertical"
android:orientation="horizontal"
android:background="#drawable/formheader">
<ImageView
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Reminder Messages"
android:textColor="#android:color/black"
android:textStyle="bold" />
</LinearLayout>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.example.sampleapp.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>
<activity
android:name="com.example.sampleapp.ItemActivity"
android:theme="#style/TitleBarTheme" />
<activity
android:name="com.example.sampleapp.ReminderActivity"
android:theme="#style/TitleBarTheme" > </activity>
</application>
</manifest>
and style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="titleBarHeading" parent="#android:style/TextAppearance">
<item name="android:textSize">17sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#444444</item>
</style>
<style name="CustomWindowTitleBarBG">
<item name="android:background">#323331</item>
</style>
<style name="TitleBarTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBarBG</item>
</style>
</resources>
setContentView(R.layout.reminderlayout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.reminderlayout);
You are using the same layout file for both the Content View and Title. Create a separate layout files for both
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>