想了解Android:将参数传递给选项卡的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于androidintent传递参数的相关问题,此外,我们还将为您介绍关于android–“如何将参数传
想了解Android:将参数传递给选项卡的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于android intent传递参数的相关问题,此外,我们还将为您介绍关于android – “如何将参数传递给drawable”或“使用渐变和可变图像创建按钮”、android – 将参数传递给AsyncTask构造函数有哪些优点/缺点?、android – 将参数传递给嵌套的导航架构组件图、android – 获取选项卡式活动中当前选项卡的编号的新知识。
本文目录一览:- Android:将参数传递给选项卡(android intent传递参数)
- android – “如何将参数传递给drawable”或“使用渐变和可变图像创建按钮”
- android – 将参数传递给AsyncTask构造函数有哪些优点/缺点?
- android – 将参数传递给嵌套的导航架构组件图
- android – 获取选项卡式活动中当前选项卡的编号
Android:将参数传递给选项卡(android intent传递参数)
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); mTabHost.setup(this,getSupportFragmentManager(),R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),MyFragment.class,null);
在addTab方法中,第三个参数是Bundle对象,并且为null.我可以使用第三个参数将参数传递给我的片段吗?
对于addTab,android api文档为空,并且不记录此参数.
在FragmentTabHost中实现它的代码是:
newTab.fragment = Fragment.instantiate(mContext,newTab.clss.getName(),newTab.args);
android – “如何将参数传递给drawable”或“使用渐变和可变图像创建按钮”
我的android项目中有一个自定义drawable,它应该是一个按钮的背景.但每个按钮也应该支持图标和文本.
到目前为止我尝试的是以下内容:
我有一个名为“btn_background.xml”的drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#ff0000"
android:endColor="#ee1111"
android:type="linear"
android:angle="90"/>
<stroke android:color="#ff0000"
android:width="1dip"/>
<size android:width="80dip"
android:height="40dip" />
</shape>
</item>
<item android:drawable="@drawable/btn_search"/>
</layer-list>
</item>
在我的布局文件中,我使用如下:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="@drawable/btn_background"
android:textColor="#ffffff"/>
这让我离得很近……但是有两个问题:
*图像在整个按钮上拉伸
*我不能只更改布局文件中的图像…所以我必须为每个图标制作一个单独的btn_whatever.xml文件?!?
我尝试的另一个解决方案是使用ImageButton而不是Button,并将背景设置为我的btn_background.xml ….这将使我能够在布局文件中选择图像…但是我不能给它一个文字….
我很高兴听到你的问题的解决方案:)
非常感谢!
解决方法:
尝试使用android:drawableLeft
(或类似的Top
,Right
,Bottom
)属性.
android – 将参数传递给AsyncTask构造函数有哪些优点/缺点?
呼叫:
new SoMetask(bitmap,integer,"somestring").execute();
类:
public class SoMetask extends AsyncTask<Void,Void,String> { private String string; private Bitmap image; private int integer; public SoMetask (Bitmap bmp,int someint,String s){ this.image = bmp; this.string = s; this.integer = someint; } protected String doInBackground(Void... params) { // whatever return "string"; } @Override protected void onPostExecute(String result){ // whatever }
}
设计,优雅,重用和性能有哪些优点/缺点?
谢谢.
解决方法
What are the advantages/disadvantages regarding design,ellegance,reuse and performance??
如果您有任意数量的相同类型(例如,您希望任务下载的字符串的几个URL),请使用参数来执行().
如果您有几个不同类型的参数,请使用构造函数参数,因此您可以利用Java的编译时类型安全性.
如果你只有一个对象传入(或者没有),这两种方法几乎相当.
android – 将参数传递给嵌套的导航架构组件图
如何将参数传递给嵌套的导航架构组件图?
假设我构建导航图以从FragmentA导航 – >嵌套,其中嵌套包含FragmentB – > FragmentC …
如果这是一个纯粹的FragmentA – > FragmentB …图,我只想用FragmentADirections.actionFragmentAToFragmentB(argument = foo)设置导航.但是一旦你转动B – >该动作就会采用零参数; C进入嵌套…
那我该怎么办?
解决方法:
全局操作可能是一种方式,但是一旦我将嵌套图形提取到它自己的.xml,我就没有按照我想要的那样工作.但结果却令人尴尬 – 只需在代码中手动添加参数即可.
与该问题相关的一个例子是:
将嵌套图保存到nested_graph.xml,它看起来像
<navigation
android:id="@+id/nested_graph"
app:startDestination="@id/fragmentB"
...>
<fragment
android:id="@+id/fragmentB"
...>
<argument
android:name="foo"
app:argType="integer"/>
<action
... // navigation action to FragmentC />
</fragment>
<fragment ... // FragmentC stuff
</navigation>
要从不同的图中将参数传递给nested_graph.xml,请说root_graph.xml
<navigation
android:id="@+id/root_graph"
app:startDestination="@id/fragmentA"
...>
<fragment
android:id="@+id/fragmentA"
... >
<action
android:id="@+id/action_fragmentA_to_nested_graph"
app:destination="@id/nested_graph">
<argument
android:name="foo"
app:argType="integer"/>
</action>
</fragment>
<include app:graph="@navigation/nested_graph"/>
</navigation>
换句话说,只需添加相同的<参数... />您希望在nested_graph中收到的root_graph操作.
android – 获取选项卡式活动中当前选项卡的编号
首先,我是Android开发的新手,我将非常感谢您的帮助.
我在android studio中有一个标签式活动,我有一个FloatingActionButton在标签活动的每个片段中添加一个Item.然后这个按钮调用一个新的Activty,我想将标签号传递给新活动,这样我就可以将它存储在数据库中.
如何获取生成新活动的选项卡号?
以下是代码:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_portal);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
mViewPager.addOnPagechangelistener(new
TabLayout.TabLayoutOnPagechangelistener(tabLayout));
tabLayout.addOnTabSelectedListener(new
TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent startNewPostActivity = new Intent(getApplicationContext(), NewPostActivity.class);
startNewPostActivity.putExtra("Fragment_Position", position_fragment);
startActivity(startNewPostActivity);
}
});
}
为了获得这个职位我正在做以下事情:
设置position_fragment = position;
但是这会返回错误的标签号.
公共类SectionsPagerAdapter扩展FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
position_fragment = position; // not good
return PlaceholderFragment.newInstance(position);
}
@Override
public int getCount() {
// Show 5 total pages.
return 5;
}
}
}
解决方法:
试试这个:
fab.setonClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent startNewPostActivity = new Intent(getApplicationContext(), NewPostActivity.class);
startNewPostActivity.putExtra("Fragment_Position", mViewPager.getCurrentItem());
startActivity(startNewPostActivity);
}
});
今天关于Android:将参数传递给选项卡和android intent传递参数的分享就到这里,希望大家有所收获,若想了解更多关于android – “如何将参数传递给drawable”或“使用渐变和可变图像创建按钮”、android – 将参数传递给AsyncTask构造函数有哪些优点/缺点?、android – 将参数传递给嵌套的导航架构组件图、android – 获取选项卡式活动中当前选项卡的编号等相关知识,可以在本站进行查询。
本文标签: