针对android–同一个Activity上的两个导航抽屉和androidstudio两个activity来回跳转这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展andoroid在非acti
针对android – 同一个Activity上的两个导航抽屉和androidstudio两个activity来回跳转这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展andoroid在非activity下结束上一个activiy、android activity-》fragment-》activity怎么从最后一个activity回退到上个fragment?、android – 不同的SoftInputMode在同一个Activity中,是否可能?、android – 使用另一个Activity中的一个Activity中获取的数据等相关知识,希望可以帮助到你。
本文目录一览:- android – 同一个Activity上的两个导航抽屉(androidstudio两个activity来回跳转)
- andoroid在非activity下结束上一个activiy
- android activity-》fragment-》activity怎么从最后一个activity回退到上个fragment?
- android – 不同的SoftInputMode在同一个Activity中,是否可能?
- android – 使用另一个Activity中的一个Activity中获取的数据
android – 同一个Activity上的两个导航抽屉(androidstudio两个activity来回跳转)
解决方法
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> <ListView android:id="@+id/right_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="end" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#111"/> </android.support.v4.widget.DrawerLayout>
还要检查文档https://developer.android.com/training/implementing-navigation/nav-drawer.html
确保使用工具栏而非操作栏
andoroid在非activity下结束上一个activiy
Context context;
this.context = context;
((Activity)context).finish();
android activity-》fragment-》activity怎么从最后一个activity回退到上个fragment?
android activity-》fragment-》activity怎么从最后一个activity回退到上个fragment?
一个activity跳转到一个fragment,然后fragment又跳转到下个activity,最后这个activity怎么回退到第一个activity。
android – 不同的SoftInputMode在同一个Activity中,是否可能?
目标是仅重新调整两个片段中的一个.
这是一个例子
活动
public class MainActivity extends Activity { ... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.frame1,new PlaceholderFragment()) .commit(); getFragmentManager().beginTransaction() .add(R.id.frame2,new PlaceholderFragment1()) .commit(); } } ...
片段:
public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { // Context contextThemeWrapper = new ContextThemeWrapper(getActivity(),R.style.noresize); // LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper); getActivity().getwindow().setSoftInputMode(WindowManager.LayoutParams.soFT_INPUT_ADJUST_nothing); return inflater.inflate(R.layout.fragment_main,container,false); } } public static class PlaceholderFragment1 extends Fragment { public PlaceholderFragment1() { } @Override public View onCreateView(LayoutInflater inflater,Bundle savedInstanceState) { getActivity().getwindow().setSoftInputMode(WindowManager.LayoutParams.soFT_INPUT_ADJUST_PAN); View rootView = inflater.inflate(R.layout.fragment_main_2,false); return rootView; } }
活动的主要布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" tools:ignore="MergeRootFrame" android:orientation="horizontal" > <FrameLayout android:id="@+id/frame1" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"> <FrameLayout android:id="@+id/frame2" android:background="#30000000" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent"> </LinearLayout>
好吧,我看到我在活动上重新定义了两次SoftInputMode,这不太可能成功.
所以,是否有可能做类似碎片的事情.getwindows.setSoftInputMode(…
对不起我的英语不好 …
解决方法
另一方面,如果您一次只在屏幕上显示其中一个片段,则onCreateView()方法可能不适合此代码.您可能想尝试将它放在Fragment方法onResume()和onPause()中.在onResume()中保存现有的软输入模式并将其设置为您想要的模式,并在onPause()中将软输入模式恢复为之前的模式.
android – 使用另一个Activity中的一个Activity中获取的数据
我从Web服务器获取某些数据,比如说Activity_1中的userName.然后我想在Activity_2中使用相同的数据
所以我把这个userName设为Public Static,并在Activity_2中使用这个
Activity_1.userName
但是当我在Activity_2中并按下Home Button并在5分钟后重新打开应用程序时,此Activity_1.userName将变为Null,因为Activity_1数据已被销毁.我得到NullPointerException
如何以简单的方式解决这个问题.
我刚刚给出了一个userName的例子,但实际上它的其他一些数据每天都在变化,比如说“当天的新闻”
许多人建议删除public static并将该userName发送为:
Intent.putExtra("user_name", userName);
但这与我正在做的不一样.我的意思是即便这样我也会得到NullPointerException吗?
解决方法:
有两种方法可以做到这一点.
>始终确保Activity1是应用程序中的起始活动.我的意思是,如果用户关闭应用程序并再次重新启动它,应用程序应该来自Activity1,从而再次获取数据.然后只去Activity2.另请注意,您可以使用AsyncTask从Activity2中的Web中获取数据.
>在SharedPreferences中保存Activity1中的数据,在Activity2中始终使用SharedPreferences读取值.
关于android – 同一个Activity上的两个导航抽屉和androidstudio两个activity来回跳转的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于andoroid在非activity下结束上一个activiy、android activity-》fragment-》activity怎么从最后一个activity回退到上个fragment?、android – 不同的SoftInputMode在同一个Activity中,是否可能?、android – 使用另一个Activity中的一个Activity中获取的数据的相关知识,请在本站寻找。
本文标签: