I set the following to visible in my onCreate method.
findViewById(R.id.noDesignsCallToAction).setVisibility(View.VISIBLE);
In the XML, the view is set to visibility gone.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:layout_below="@id/toolbar"
android:id="@+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/go_ahead_create_something_n_it_s_really_easy_n_just_click_here_to_get_started"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/noDesignsCallToAction"
android:padding="10dp"
android:textSize="14sp"
android:typeface="sans"
android:visibility="gone"
android:onClick="LaunchCustomizer"
android:gravity="center_vertical|center_horizontal" />
</LinearLayout>
Why won't the textview appear as visible in my app?
Make sure you set the content view first. Otherwise you'll get an NPE as a result of the ID not being found in the active layout.
Use an instance (don't call findViewById(id).setVisibility()
as it uses more memory compared to caching the TextView as a field) and then set the visibility.
setContentView(R.layout.layout);
TextView temp = (TextView) findViewById(R.id.noDesignsCallToAction);
temp.setVisibility(View.VISIBLE);
Inflate it and then set its visibility.
setContentView(R.layout.something);
TextView tv = (TextView) findView...;
tv.setVisibility(View.VISIBLE);
and maybe string res is empty ?
在布局文件中更改textview的textColor或检查是否有任何视图与textview不重叠。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.