gpt4 book ai didi

android - 带有自定义 ActionBar 的半透明 ImageSlider

转载 作者:行者123 更新时间:2023-11-30 02:29:42 25 4
gpt4 key购买 nike

我正在尝试使用具有以下功能的 PageAdapter 获取 ImageSlider Activity :-

  1. 半透明背景。
  2. 带有 TextView 和 ImageButtons 的半透明自定义操作栏。

我面临的问题:-

  1. 为了使 Activity 半透明,我添加了 android:theme="@android:style/Theme.Translucent<activity> list android:background="#20000000"XML 布局 文件中。但是在这样做之后 getActionBar()在我的 onCreate()方法返回 null。如果我删除 android:theme="@android:style/Theme.Translucent然后 Activity 不再是半透明的而是getActionBar()现在正在工作。

我正在使用 getActionBar()膨胀一个自定义的半透明操作栏,所以现在我可以获得半透明 Activity 或一个自定义操作栏,而不是同时获得它们。

    我的自定义操作栏中的
  1. TextView 用于显示当前图像中的所有图像,例如 1 out of 5 并向右滑动以获得 5 分之 2,依此类推。

但有时它会正确显示,有时只是随机数字。

我的代码:-

TextView header;
int count=0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Getting Action Bar
ActionBar mActionBar= getActionBar();

LayoutInflater minflate =(LayoutInflater) mActionBar.getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
mview = minflate.inflate(R.layout.albumactionbar,null);

mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,ActionBar.DISPLAY_SHOW_CUSTOM|ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_TITLE);
mActionBar.setCustomView(mview, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));

header =(TextView)mview.findViewById(R.id.action_text);

setContentView(R.layout.albummainview);
}

albumactionbar.xml:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_ab"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/album_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_back"
android:layout_alignParentLeft="true"
android:background="@color/Translucent"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/action_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_gravity="center"
android:text="Gallery Count"
android:textSize="18sp"
android:layout_centerInParent="true"/>
<ImageButton
android:id="@+id/album_after"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_after"
android:layout_alignParentRight="true"
android:background="@color/Translucent"
android:layout_gravity="center"
/>


</RelativeLayout>

custom_ab.xml:-

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >



<gradient
android:startColor="#FF000000"
android:endColor="#00000000"
android:angle="270"
/>

</shape>

现在在 MyAdpater 中,我正在更改 header自定义操作栏的 TextView 值:-

public class AlbumAdapter extends PagerAdapter

{

Context context;

public AlbumAdapter(Context context){
this.context = context;

}


@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub

LayoutInflater inflater = ((Activity)context).getLayoutInflater();

View viewItem = inflater.inflate(R.layout.albumitemview, container, false);

//header is the custom action bar's text view.
header.setText((position+1)+" out of "+count);

.....

}
}

所以请指导我解决这两个问题,关于问题 2,它是更改 textView 值的正确位置吗?

最佳答案

对于第一个问题,您可以通过 <color name="Transparent_Black">#50000000</color> 在 styles.xml 中更改 actionbar 的颜色。例如,然后添加 getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);在你的 Activity 中 onCreate()。我用过这个,效果很好。当你这样做时,你可以通过 getActionBar().setTitle("") 添加标题相反,如果标题。

对于你的第二个问题,你只需要添加一个 ViewPager.OnPageChangeListener到你的 ViewPager,它有一个方法 onPageSelected(position) ,您可以在那里更新您的 header .

所以如果两个问题都解决了你可以添加getActionBar().setTitle((position+1)+" out of "+count)给你的onPageSelected(position)方法。

关于android - 带有自定义 ActionBar 的半透明 ImageSlider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27467703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com