Here is a pic of android applicationbar i like ( I mean the part where settings is written on, not sure if applicationbar is the right name :) )
http://oi50.tinypic.com/ehwwpc.jpg
Some apps i have downloaded also have the exact same bar so im guessing its a predefined theme but when i make a project (theme.holo) then my applicationbar is just totally black.
So my question is how do i get the same project bar?
Thank you!
Edit:
I found that all apps are opensoruce and i looked out settings apps manifest for android 4.0.4, same as mine.
Here it is: https://android.googlesource.com/platform/packages/apps/Settings/+/android-4.0.4_r2.1/AndroidManifest.xml
Whats strange is that it uses the same theme i do: android:theme="#android:style/Theme.Holo"
... but still the titlebar is different. There must be another attribute somewhere that defines the titlebar? Does anyone have an idea? :)
The title of the activity can be defined in the Manifest file, and it should be android:label property. For example:
<activity
android:name=".MainActivity"
android:label="#string/TitleBarText" />
TitleBarText is the android string resource that contains the name of the title.
If you wish to do it from code, you can just do the following in the onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
setTitle("Title Bar Name");
setContentView(R.layout.activity_main);
}
To create a custom title bar, refer to: this and this
Related
How to hide Android status bar in native game written with gomobile?
I am experimenting with a simple native Android game written in pure Go using the gomobile tool. It should be able to use the full screen for rendering frames. However I could not find an API to hide the status bar from the native app.
Has anyone tackled this issue? If so, please share the directions.
Create a Empty Activity .
Go and find
android:theme="" on Activity XML Files
Set it to #style/Theme.AppCompat.NoActionBar
Pro Tip :
dont know other people but I always delete
Menu/Menu_Activity.Xml
That Contains Menu XML files !
Also Remove Menu.OnClick Codes Located on The Class of Your
Activity
Update :
Emm ... did you change :
public class Setup extends ActionBarActivity {
to
public class Setup extends Activity {
???
On the manifest add: theme: Theme.AppCompat.NoActionBar
For each activity page in which you dont want to show the status bar
This is how to disable the Android status bar in a native application written with gomobile:
Add this exact theme to AndroidManifest.xml:
<activity android:name="org.golang.app.GoNativeActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
</activity>
Basically, I have an app with two Activities.
#1 - MainActivity
This has a solid black background and a button.
When the button is pressed TransparentActivity should be presented.
#2 - TransparentActivity
I want this to be transparent (so the phones normal UI can be seen through).
I've tried using the following code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Translucent);
setContentView(R.layout.activity_trick);
}
But it causes the app to crash with an NullPointerException.
Try1:
Make super.onCreate(savedInstanceState); call after setTheme(android.R.style.Theme_Translucent);. So do as:
setTheme(android.R.style.Theme_Translucent);
super.onCreate(savedInstanceState);
Try 2:
If that doesn't work, I find the following way easiest to make my activity transparent:
<activity android:name=".your.activity.declaration.here"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
Basically add android:theme="#android:style/Theme.Translucent.NoTitleBar" to your activity declaration in manifest. I can see that you are trying to do a similar thing programatically but by specifying it in manifest never crashed for me. If it does, then there might be other reasons.
Hope it helps.
AppCompatActivity hasn't the Theme_Translucent(maybe the Theme_Translucent is null),you should create your own style.
In any application the add/edit will be comparatively having lesser inputs. I have seen that the application, esp., calendar, are using clever strategy to show these as simple dialog, so that the user may not notice that there is empty space in the designed form
As shown below
My question is, how to make it happen?
What I'm doing is I extend DialogFragment:
public class AboutFragment extends DialogFragment { ... }
I also have an activity that contains that fragment. And when the dialog/activity needs to be called, this method decides how to display it:
public static void showAbout(Activity parent) {
if (isTablet) {
AboutFragment aboutFragment = AboutFragment.newInstance();
aboutFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogTheme);
DialogUtils.showDialog(parent, aboutFragment);
} else {
Intent aboutIntent = new Intent(parent, AboutActivity.class);
parent.startActivity(aboutIntent);
}
}
How to decide whether it is a tablet, is totally up to you.
This technique is explained in the documentation.
In my opinion the best approach here is to use
<!-- Theme for a window without an action bar that will be displayed either full-screen
on smaller screens (small, normal) or as a dialog on larger screens
(large, xlarge). -->
"android:Theme.Holo.Light.DialogWhenLarge.NoActionBar"
The best/easiest solution I've found is to always use an Activity, and based on screensize (and version), change your Theme parent.
in res/values/themes.xml
<style name="Detail.Theme" parent="#android:style/Theme.Holo.Light" >
...
</style>
and in res/values-large/themes.xml
<style name="Detail.Theme" parent="#android:style/Theme.Holo.Light.DialogWhenLarge" >
...
</style>
use Context.setTheme method to set them programmetically. As the doc says
this should be called before any views are instantiated in the Context
(for example before calling.
So, to switch between themes need to call setTheme before onCreate
public void onCreate(Bundle savedInstanceState) {
// check screen size
setTheme(dialogTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
As #StinePike answered, setting a dialog theme programatically doesn't do any use (to me), as it shows a wierd black screen behind the dialog, rather than a dimmed background (as shown in the question). This is obviously a bug.
Instead of trying to set it programatically, or in style.xml, and pretty much everywhere except for AndroidManifest.xml, I did the reverse, which has worked for me.
(the solution which I took from the marvelous solution of the above issue)
The simplest solution (that works) as follows:
1. Make the activity a dialog by default through AndroidManifest.xml:
e.g., in the AndroidManifest.xml:
<activity
android:name="com.example.MyActivity"
android:label="#string/title_activity_mine"
android:theme="#android:style/Theme.DeviceDefault.Dialog">
...
</activity>
2. On starting the activity, set the theme to default if device is not a tablet.
if (!(isTablet(this)) {
setTheme(defaultTheme);
}
super.onCreate(savedInstanceState);
...
Note:
solution will work with custom styles defined in style.xml.
Ref:
How to detect device is Android phone or Android tablet?
Dialog with transparent background in Android
Issue 4394 - android - setTheme() does not work as expected
PS: final app on tablet and phone is as follows:
Use a DailogFragment and then control how its shown with setShowsDialog()
I would like to place the logo for my application in the actionbar at the top of the screen. Currently displayed is the default green android launcher icon.
I have tried the following but saw no change:
I went into my manifest file and altered the android:icon code...
<application
android:allowBackup="true"
android:logo="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
This did not work, So I then created an ActionBar object within my code and used the setIcon method.
ab.setIcon(R.drawable.logo);
However the above line of code generates the following runtime error:
**java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.waitronproto3/com.example.waitronproto3.MainActivity}: java.lang.NullPointerException
**
Can anybody see why this is happening, The resource R.drawable.logo exists because I can see it in the folder and no errors are generated within the IDE.
Any help is much appreciated.
Yeah, there is no android:logo property as far as I know. You can't just create an ActionBar... have you used this?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...);
getActionBar().setLogo(R.drawable.logo)`
}
Everything was right except I forgot to get a reference to the ActionBar. The code below solved the problem.
ab = this.getActionBar();
ab.setIcon(R.drawable.logo);
I am using ActionBarSherlock (ABS) and would like to add a dialog to my application as one can see in the ABS Demos Sample application provided by the project. The dialog sample look like this:
I created an activity myself. Here is relevant source code:
public class Dialog extends SherlockActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Sherlock___Theme_DarkActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dialog);
}
}
For some reason, Android forces me to add setTheme() although the ABS sample does not do this. If I leave it out, I will run into the following error.
java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
My AndroidManifest.xml has the following settings, which are very similar to the ones from the ABS sample.
<activity
android:name=".activities.Dialog"
android:label="#string/title_activity_dialog"
android:theme="#style/Theme.Sherlock.Dialog" >
</activity>
The following screenshot shows how my dialog activity looks like.
I am using ActionBarSherlock 4.1.0 with maps support, the Android Support library v4.
Question: Can you figure out, why it looks so different?
Dark vs. light user interface
Transparent vs. opaque background
With and without actionbar
Update:
The ABS sample starts the dialog activity as follows:
protected void onListItemClick(ListView l, View v, int position, long id) {
Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position);
Intent intent = (Intent) map.get("intent");
startActivity(intent);
}
I start the dialog activity as follows:
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(R.string.title_menuItemDialogActivtiy)
.setIcon(R.drawable.ic_action_dialog)
.setIntent(new Intent(this, Dialog.class))
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
Meanwhile, I saw that this pattern is deprecated. Instead, I could use a DialogFragment. The question that occurs here: How can I integrate the fragment with the action menu item?
Alternative solution:
I decided to use a DialogFragment instead of an Activity as I estimate it to be more "future-safe". I basically followed the very informative tutorial Using DialogFragments (posted June 3, 2012), which I like to recommend as perfect starting point for any interest reader. Further, I like to add related and useful posts:
Validating user input
Softkeyboard vs. separate DONE button
The output you are seeing definitely comes from setting the Theme in Java code (which will override the value set in XML). I just stood up the following sample application (this is literally all there is) and replicated the issue by adding the extra setTheme() call.
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Dialog"
android:theme="#style/Theme.Sherlock.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And the Dialog...
public class Dialog extends SherlockActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView text = new TextView(this);
text.setText("This is a dialog!");
setContentView(text);
}
}
Now as to why you got an exception without that extra method, that's another matter (and quite strange). As you can see it should work with as little code as I provided above.
Perhaps make sure that both the library project and your project are being compiled with at least Android 4.0 (API 14) as this is a requirement of the library.
Beyond that, if you just want to show a Dialog in your application, does it need to be a themed Activity? This is not common. You can always create a simple Dialog or AlertDialog subclass to display as well. Take a look here for more information...
Try setting a theme for the application.
<application
android:theme="#style/Theme.Sherlock"
The dialogue should inherit the theme. If you've already set that then remove the android:theme tag in the activity declaration and the setTheme() call and see what happens. The reason you get the error without setTheme is because SherlockActivities must have one of the themes in the error message and you had it set to something else in the manifest setTheme() overrode this before you got into trouble.