android-context

How do I prevent Android device Display size scaling in my app?

北慕城南 提交于 2020-05-09 05:18:47
问题 I'm developing an app with React Native for both iOS and Android, and I am trying to prevent device-specific scaling of the display in the app. For text/font size scaling, putting the following code in the root-level App.js file solves the issue for both iOS and Android: if (Text.defaultProps == null) { Text.defaultProps = {}; } Text.defaultProps.allowFontScaling = false; However, Android devices have the following Display size setting that is still being applied: I've tried (unsuccessfully)

Why is ContextThemeWrapper now restricted to the Support Library group?

a 夏天 提交于 2020-04-08 18:51:04
问题 I started using a ContextThemeWrapper to apply a style dynamically to an ImageButton ; based an answer to another question of mine, and answers to other similar questions. ContextThemeWrapper wrapper = new ContextThemeWrapper(getContext(), mStyleRes); mImageButton = new AppCompatImageButton(wrapper, null, 0); But recently a lint error started appearing on the ContextThemeWrapper constructor stating: ContextThemeWrapper can only be called from within the same library group (groupId=com.android

Why is ContextThemeWrapper now restricted to the Support Library group?

巧了我就是萌 提交于 2020-04-08 18:49:49
问题 I started using a ContextThemeWrapper to apply a style dynamically to an ImageButton ; based an answer to another question of mine, and answers to other similar questions. ContextThemeWrapper wrapper = new ContextThemeWrapper(getContext(), mStyleRes); mImageButton = new AppCompatImageButton(wrapper, null, 0); But recently a lint error started appearing on the ContextThemeWrapper constructor stating: ContextThemeWrapper can only be called from within the same library group (groupId=com.android

Why is ContextThemeWrapper now restricted to the Support Library group?

梦想与她 提交于 2020-04-08 18:48:54
问题 I started using a ContextThemeWrapper to apply a style dynamically to an ImageButton ; based an answer to another question of mine, and answers to other similar questions. ContextThemeWrapper wrapper = new ContextThemeWrapper(getContext(), mStyleRes); mImageButton = new AppCompatImageButton(wrapper, null, 0); But recently a lint error started appearing on the ContextThemeWrapper constructor stating: ContextThemeWrapper can only be called from within the same library group (groupId=com.android

How to get Context in Android MVVM ViewModel

﹥>﹥吖頭↗ 提交于 2020-04-05 07:35:42
问题 I am trying to implement MVVM pattern in my android app. I have read that ViewModels should contain no android specific code (to make testing easier), however I need to use context for various things (getting resources from xml, initializing preferences, etc). What is the best way to do this? I saw that AndroidViewModel has a reference to the application context, however that contains android specific code so I'm not sure if that should be in the ViewModel. Also those tie into the Activity

What is the role of attachBaseContext?

断了今生、忘了曾经 提交于 2020-02-23 10:25:11
问题 I am confused about why do we use attachBaseContext in android. It would be a great help if someone could explain to me the meaning for the same. 回答1: The attachBaseContext function of the ContextWrapper class is making sure the context is attached only once. ContextThemeWrapper applies theme from application or Activity which is defined as android:theme in the AndroidManifest.xml file. Since both Application and Service do not need theme, they inherit it directly from ContextWrapper . During

Best way to get an Application Context into a static method in Android

你说的曾经没有我的故事 提交于 2020-02-18 05:40:34
问题 I'm working on an Android application that has several Activities. In it I have a class with several static methods. I would like to be able to call these methods from the different Activities. I'm using the static methods to load data from an xml file via a XmlResourceParser. To create a XmlResourceParser requires a call on the Application Context. So my question is, what is the best way to get a reference to the Application Context into the static methods? Have each Activity get it and pass

Android: Passing context to helper class results in NPE

為{幸葍}努か 提交于 2020-02-07 17:15:20
问题 I am creating an Android app and I am trying to use a SettingsManager class to read and write preferences. To use this, I have to pass context to this SettingsManager in order to use the SharedPreferences API. However, my code keeps giving me a NullPointerException . Can anyone tell me why? Main.java @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_status); mNavigationDrawerFragment = (NavigationDrawerFragment)

Context being passed into method for getAssets() is null

你离开我真会死。 提交于 2020-01-25 11:34:10
问题 In the code below, the getPieceTextFile() method takes an Activity context parameter, however when used, the context passed in appears to be null and leads to a NPE. Any suggestions why would be greatly appreciated. The LogCat output and code listing are shown below. LogCat 01-03 13:48:47.223: I/dalvikvm(571): threadid=3: reacting to signal 3 01-03 13:48:47.233: I/dalvikvm(571): Wrote stack traces to '/data/anr/traces.txt' 01-03 13:49:30.073: I/System.out(571): Asset Manager/IS not work. 01

Calling a method in a fragment from a separate class

做~自己de王妃 提交于 2020-01-17 02:41:24
问题 What's the best way to call a method inside a fragment from a different class? I passed the context via getActivity() into the class. Something along the lines of ((Fragment) ((Activity) context).getMainFragment()).Method(); This just doesn't look right.... 回答1: I think you can do something like this: Create interface OnMyDialogClickListener and class MyDialogFragment , which will call methods of created interface public class MyDialogFragment extends DialogFragment { private