android-activity

How to get screen width and height

六眼飞鱼酱① 提交于 2019-12-29 02:45:59
问题 I tried to use following code to get screen width and height in android app development: Display display = getWindowManager().getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); but I got NullPointerException for my display , why? how to get screen width and height then? 回答1: If you're calling this outside of an Activity, you'll need to pass the context in (or get it through some other call). Then use that to get your display metrics:

How to go to fragment from activity

天大地大妈咪最大 提交于 2019-12-28 23:37:48
问题 I am using ActionBarSherlock, I am not able to go to class that extends SherlockFragment from activity I need to move from Activity to fragment class Here is my Activity class Intent notificationIntent = new Intent(context,MessagesFragment.class); And the Fragment class is like public class MessagesFragment extends SherlockFragment implements OnItemClickListener { // Layout parameters declaration private PullToRefreshListView lv_messages; private ImageView iv_no_data; private LinearLayout ll

Activity navigation: custom animation with popEnter and popExit like fragments

戏子无情 提交于 2019-12-28 18:23:10
问题 Changing activities with an animation is possible using the code below: Bundle animation = ActivityOptions.makeCustomAnimation(App.getContext(), R.anim.enter_from_right, R.anim.exit_to_left).toBundle(); startActivity(intent, animation); For fragments you can do something similar on FragmentTransaction: // ... transaction.setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left); // ... This works! But I'd like to have an animation when pressing back (pop from backstack). For fragments

Fragment and parent activity life cycle together

久未见 提交于 2019-12-28 16:07:19
问题 I was following these four topics Creating a Fragment, Handling the Fragment Lifecycle , Managing the Activity Lifecycle and Pausing and Resuming an Activity. So I am in a little doubt about this. My question is If A Activity call B Activity through Intent but A does not call finish() method then A will be in Pause state if B is Transparent or SemiTransparent and in Stop state if B is Opaque . Am I right? If A Activity contains Fragment F then if A will go to Pause state then F will go to

Common Clickable Header for All Activities in Android

放肆的年华 提交于 2019-12-28 13:35:14
问题 I have an application with a common Header in all layouts. I want that whenever the user clicks at the the ImageView with id btn_home , the app will go back to a specific activity, my "Main" for instance. What is the best way to do that? I know that I can define the onClick(View v) for every activity, but maybe there is a better way to do that. Even making every activity be some (via heritage) other that has the onClick(View v) defined sounds bad. header.xml <RelativeLayout ...>

Differentiating between an Activity launch from home screen or from another activity from App

你说的曾经没有我的故事 提交于 2019-12-28 12:28:52
问题 I need to know a generic way to distinguish between a call of activity from launcher and a call from another activity from inside my app, or a BACK on the activity stack Anyone? this is bugging me for quite a while now and i need to put it to rest... Thanks in advance JQCorreia 回答1: In the onCreate of your Activity, call getIntent() . If the Activity is started from the launcher (home screen) the values for getAction() will be android.intent.action.MAIN and the getCategories() will return a

Android: Your content must have a ListView whose id attribute is android.R.id.list

谁都会走 提交于 2019-12-28 11:51:32
问题 I'm getting this run-time error and I'm really struggling to get to the bottom of it: "Your content must have a ListView whose id attribute is android.R.id.list". Here is my code: public class ShowAllJobsInArea extends ListActivity{ Context context; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.show_jobs_in_area); context=getApplicationContext(); String area=Cookie.getAreaSelected(); final ProgressBar thinger=(ProgressBar)

How to change all the activity transitions at once in Android application?

随声附和 提交于 2019-12-28 08:08:05
问题 I know I can change activity transition using the following code right after startActivity() or finish() activity.overridePendingTransition(R.anim.activity_close_enter, R.anim.activity_close_exit); But if I have ten activities in my app, I have to do that ten times; and it is quite hard to modify. So I'm wondering if there is a way to set transition for all activities within the application at once. Is there any corresponding configuration in AndroidManifest.xml? Thanks! 回答1: You want to

easiest way to use svg in android?

ぐ巨炮叔叔 提交于 2019-12-28 07:47:08
问题 I have found a myriad of libraries in order to use svg in Android and avoid the frustrating creation of different resolutions and dropping files for each resolution, this becomes very annoying when the app has many icons or images. Can anyone be as kind to give a step by step process of the simplest to use library for using SVG in Android, I'm sure this will help many others too. Also I use Android Studio and Illustrator for generating my icons and images. 回答1: First you need to import svg

What's the difference between windowBackground and background for activities style?

纵然是瞬间 提交于 2019-12-28 05:50:06
问题 I have a background set for all of the activities of the app by using the "android:background" parameter in the styles and setting the theme of the application to link to this style. All worked well, till I've noticed that for a dialog with a list of items, it makes each item to have the full size of the background . After changing the parameter being used to "android:windowBackground" it seems to work fine in this case too. Why does it occur? What is the difference between the two? Also ,