![](/img/trans.png)
[英]How to set the attribute "android:scrollbars" programmatically for a view in Xamarin Android C#?
[英]How to set “android:scrollbars=vertical” programmatically?
我想以編程方式在EditText
動態設置scrollbars
,但我沒有找到這個 api 作為 setscrollbars。 誰能告訴我這是否可以以編程方式完成?
android:scrollbars="vertical"
這可能嗎? 我怎樣才能以編程方式實現這一目標?
我也在尋找一種以編程方式執行此操作的方法。
似乎來自http://developer.android.com/reference/android/view/View.html#attr_android:scrollbars這是不可能的,因為那里沒有提到相關的方法。
通過描述聽起來不錯的唯一方法是:
View.setVerticalScrollBarEnabled(boolean)
但就我而言,它不起作用。 但這可能取決於布局和使用方式。
我現在正在考慮有兩種布局:一種將屬性設置為“none”,另一種設置為“vertical”。 然后在代碼中我可以決定使用哪個。
final TypedArray typedArray = context.obtainStyledAttributes(null, new int[]{});
try {
Method method = View.class.getDeclaredMethod("initializeScrollbars" , TypedArray.class);
method.invoke(this, typedArray);
}catch (Exception e) {
}
typedArray.recycle();
setVerticalScrollBarEnabled(true);
你必須用你自己的覆蓋 android:scrollbarTrackVertical 和 android:scrollbarThumbVertical drawable。 您可以使用代碼或樣式來完成。
這是一個顯示如何自定義按鈕的鏈接。 滾動條的原理是類似的。
以編程方式:
RecyclerView mRecyclerView =rootView.findViewById(R.id.your-recycler-view);
if(mRecyclerView!=null){
mRecyclerView.setVerticalScrollBarEnabled( true );
}
在 XML 中:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:scrollbars="vertical"
android:layout_height="wrap_content" />
其他滾動條:
android:scrollbars="vertical"
android:scrollbars="horizontal"
android:scrollbars="vertical|horizontal"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.